strawman_redherring

Why you shouldn’t learn MVC

Earlier today Rob Connery posted about why he thinks You Should Learn MVC.  Rob is a great guy and we always have lively discussions whenever we meet at conferences.  I was in the middle of writing a long comment on his blog when I decided it might be better as it’s own post.

I have to say Rob, once again, another great post!  Another great use of straw man arguments and red herrings.  Come on really?  You are going to trot out jQuery as a reason to try MVC?  Why not say “Use MVC because it runs on Windows and works with IIS”.  Come on, at least use real arguments if you are going to make the case for MVC.  I’m sure you know that jQuery works wonderfully with WebForms.  People like Rich Strahl, Dave Ward and others have a ton of great blog posts on the topic.  I even have a few myself.  jQuery is a valid argument if you are trying to sell people on adding more JavaScript, but the argument as framed does not make the case for MVC.

Wow.  You can use your own view engine in MVC.  Good to see that MVC didn't break a basic feature we have had in ASP.Net since the 1.0 days.  Nobody using ASP.Net is forced to use WebForms for page rendering.  It seems that in Rob’s world, projects like Umbraco, Castle, and Visual Web GUI are the only people smart enough to figure that out. It is perfectly valid for a page or a control, or heaven forbid an HttpHandler, to use a different rendering engine for generating the HTML.

Non-validating Html - Really, that is the best you have?  To paraphrase a quote from Rob - "Non-validating HTML is as Non-validating HTML does". If you want to write code that validates in WebForms, that is completely possible today.  If you don’t care whether your page validates then moving to MVC isn’t going to make you suddenly start caring.  I can throw a div inside a span and use capital letters in my attribute names and even use the bold tag and MVC will merrily spit it out to the browser.  Sure, WebForms has a ton of crappy controls that will render garbage, but that is not the fault of WebForms.  It is the fault of the control developers and the people who use those controls.  There are lots of controls that render great markup – and people who care about their markup will either use a good control, or hand code their html.

Amazing, you can use IoC with MVC.  Wow.  I wish you could do that with Asp.Net and web form apps.  It's is mind-blowing that all these IoC containers were written before MVC came along.  Like they just knew that possibly someday, someone would be able to use them, if only MS would create a different web framework - or rather slap a different front end on ASP.Net.  I guess I better stop using IoC with my webform apps since it is not possible.

I must say I agree with you about WebForms being one giant pile of abstractions, and frankly I am tired of it. Enough already.  Let's get rid of these damned abstractions. Why, here I am using these alphanumeric characters, when we all know that it is just an illusion, a sham a hoax.  There is no such thing as a character to a computer.  There is only 1 and 0.  Wait... that's not right either.  There is only some voltage level that is not 0 and 0.  or maybe it is 2 different magnetic orientations, or a pit and the absence of a pit.  Whatever - I digress.  We live and work in a world of abstractions.  All of computer science is about abstractions.  Rob has climbed the Mt Everest of abstractions and declared that one tiny snowflake sitting on the top is bad and must be replaced.  You have suddenly declared that the top floor in our Tower of Babel is faulty and that this new penthouse suite is suddenly the one true path to heaven.

As for me and thousands of other ASP.Net developers, we are quite satisfied with our current abstraction.  It makes it easy to do a lot of tasks.  If I find the abstraction too leaky in places, then I push the abstraction out of the way and roll my own.  Is this any different than what Chad and Jeremy did with FUBU MVC?  But in most cases, I don’t need to go quite that far.  I am quite comfortable writing an HttpHandler or an HttpModule for those cases where the webform defaults are getting in my way.  I don’t require a whole new framework and a whole new mindset to get things done.  I can use WebForms where they make life easy and dive down in the weeds when I really need fine-grained control.

Hey look at those nice URLs they generate in MVC.  Boy, those are slick.  No, really, they are.  I’m not being sarcastic or anything.  You really should check them out.  But you know what – you can have them in WebForms as well.  Scott Allen has a great MSDN article that discusses this very topic.

So enough already of the red herrings, the straw man arguments and the downright deceptive use of facts.  How about a real argument about using MVC that doesn't first assume complete web illiteracy on the part of ASP.Net developers, but that somehow, if they use MVC those same brain-dead developers will suddenly become programming geniuses. If they were afraid to use jQuery before, they won’t use it just because they are in MVC.  If they didn’t care about testing or HTML or clean URLs, MVC is not going to make them see the light.  MVC is a tool.  Good at some things, bad at others.  In the hands of a master it will do great things.  In the hands of someone who doesn’t care about his craft then MVC will be a nice diversion and yet another excuse for creating bad code.

So, lest you think I am against MVC, let me assure you I am not.  I am against all of the same ol’ tired excuses about why people should jump to MVC.  Every abstraction is about making tradeoffs, and make no mistake about it – MVC is an abstraction.  Some people will claim it is a good abstraction, others will disagree, but at the end of the day the MVC team had to decide what was most important to them.  Testability was clearly high on the list (Of course if you listen to Chad and Jeremy, it wasn’t high enough on the list).  Clean URLs and a more restful like interaction was also important.  Hiding the stateless nature of the web and leveraging reusable components – not so important. 

So why should you at least learn MVC?

It will expose you to a different architecture.  MVC definitely has its place – whether you are talking about desktop apps or web apps.  MVC leads you to think about keeping a clean separation between different application concerns.  It however doesn’t force you to do so.  It is still possible for you to completely violate those rules, but it at least starts you out on the right path.  WebForms on the other hand does not impose or suggest any such constraints.  It is easy to get in trouble if you are not careful.

You will be forced to become intimately familiar with HTML and HTTP.  This is great if you don’t already know it.  I am a big believer in understanding how things work.  However, for those that already have a good grasp of HTML this is a little overkill.  I have a decent understanding of how the engine in my car works, but I don’t want to have to put it together every-time I want to drive somewhere.  I trust the auto manufacturer to create the proper level of abstraction for me.  I know what HTML is supposed to look like, but I don’t want to remember exactly which attributes can be used for a dropdown list.  What events are available to me and how that data is returned.  If I can abstract that away, it is a good thing.

MVC promotes unit testing.  It is designed as much as possible, to get out of the way and make testing simple.  This is not the case with WebForms.  In WebForms, it is possible to do testing, but it will take some effort.  Is that enough to get you to give up some of the abstractions that WebForms provides?  For me it is not.  That may change in a couple years, but I suspect that instead what will happen is that MS will invest some time in addressing this issue in WebForms.  The ASP.Net team learned a lot during the development of MVC and I know that they are already working on incorporating some of this knowledge back into the WebForms platform.

MVC will make you see how much you take for granted with WebForms. I recommend that everyone should live outside their home country for a little while.  You will either learn to appreciate where you are from or you will find out that the grass is truly greener on the other side.  In either case, you will come out ahead.  I have had the privilege to have worked in many different development environments and programmed in many different languages.  I appreciate the tools I have chosen because I have seen what else is available.  I can articulate why I like VB over C# and why I like ASP.Net over J2EE.  But I still think it is healthy to keep looking at alternatives.  In the end it will make you a better coder.

So in summary, you really should checkout MVC.  But not for the reasons Rob articulated.  You should explore MVC because in the end you might just learn something that will make you a better web programmer, no matter what platform you choose.