I’m never shy about my opinion – why start now? I’ve been reading a lot of posts flying about on whether you should learn MVC, Summing up the differences so you can decide when to use it, I even found a post that offers a scorecard approach! I remember reading the latter post thinking to myself “how can you possibly put a number next to Testability? And why it is only 2 more points than “using a RAD designer”? Isn’t this missing the entire point?
I felt the need to speak up a bit so I left a comment on DotNetKicks:
Please don’t use this “scoring” chart with respect to MVC and WebForms. Honestly – you can’t “score” something like “should I care about Testability” (which rates an 8) against “do I need to use this Server Control” (which scores a 10). There are so many problems with approaches like this – really the only answer is to *try it* and see if it works for you or your org.
Today I read a post on StackOverflow which was pretty contentious wherein the author says:
I’ve been fiddling with ASP.NET MVC since the CTP, and I like a lot of things they did, but there are things I just don’t get…
<snipped ugly viewcode>
Am I doing something wrong? Because I spent many dark days in classic ASP, and this tag soup reminds me strongly of it.
Everyone preaches how you can do cleaner HTML. Guess, what? 1% of all people look at the outputted HTML. To me, I don’t care if Webforms messes up my indentation in the rendered HTML, as long as I have code that is easy to maintain…This is not!
I have definite opinions on this, and today you get to read them. Note that I pushed Scott Hanselman really hard when we wrote our book (which I think is shipping today!) to come out AND SAY SOMETHING (Chapter 3 – a discussion on MVC and WebForms – and he did an amazingly good job). It’s too easy to think “hey – I’m Microsoft – I need to stay balanced here so I don’t offend” and there’s merit to that.
I, on the other hand, think we should also be able to speak our minds. In that light, I present to you my latest effort at getting in trouble: why you need to read this post, get up, and learn what MVC is all about (if you don’t already know).
The Great Lie
WebForms is a lie. It’s abstraction wrapped in deception covered in lie sauce presented on a plate full of diversion and sleight of hand. Nothing you do with Webforms has anything to do with the web – you let it do the work for you.
This, friends, is a big deal (at least to me): You’re working in a lie. The web is *not* stateful and works with this stuff called HTML sent across wires using another thing called HTTP – you need to know this, love this, and feel it at the bone level. I understand this sentence right here is probably making some of you squirm – please continue squirming (I’ll wait).
If you’re still squirming, then perhaps web development isn’t for you (meant very respectfully and kindly – not being snarky). I say this because you shouldn’t work in a sausage factory if you’re allergic to pork, beef, and ground up animal parts. Nor should you put a wig on your cat and hope that it can sing like Susan Boyle.
These are self-deceptions put in place to make you feel better about something lacking, and it’s usually not healthy. If you’re thinking that you don’t need to know HTTP/HTML to work on the web… you’re doing it again! Please see 2 sentences ago.
If you’re still thinking it – your cat needs a new wig.
MVC Is Elite-test?
I’m sure that WebForms people are probably thinking I’m being a bit of a sh** right now – and I’d like to speak to that. The title of the post here is “You Should Learn MVC” – not that you have to use it (although I wish you would – it’s tons of fun!). That’s all I’m asking – for you to learn it; I’m not telling you that you’re a bad person if you don’t use it (only that you put wigs on your cat).
MVC Is Full of Tag Soup?
Once again, I’ll say this: Spaghetti is as Spaghetti does. I don’t like to see a bunch of if’s and fors on my View the same as any other geek. This, friends, is up to you! Not the platform! Please read this: markup is up to you, as with everything else in MVC. Yes it’s not drag and drop – but nothing ever is in life! It’s new, it’s different – it’s not 1999 if only because we have the power of C# now – not VBScript.
I’m not afraid of HTML – and you shouldn’t be either. Respect it when putting code to page and use DRY as your guide. We can make it through this, together. You can bring your cat, too.
7 Reasons To Stop Calling Me A Jerk
Hopefully you’re still here, and hopefully you’re thinking “enough of the blather already – gimme something to sink my teeth into”. So here goes:
1 – Testability. No – not talking about the TDD variety, just testing in general. If you’re “not a testing person” that’s OK – the rest of the computer science world has embraced the idea that “testing what we build is a pretty good idea”. You don’t really want your clients to catch that silly “InvalidCastException” do ya? There’s LOTS of reasons to want to test – again not TDD – just good old Unit Testing! It’s easy peasy with MVC and this alone should pull you in to at least check it out – along with why testing can save you time and money.
2 – Control over HTML. I’m sure you’ve heard this before – mangled ID’s, non-validating HTML, etc. Why is this important? Because you might want to use client-side programming for something! I won’t bang this gong for too long – but it’s a lot more than “making ViewSource look pretty” – you’re communicating with super-finicky creatures (browsers) that love to argue – being able to smith the markup experience makes you a more valuable developer!
3 – Extensibility. Literally every part of MVC Is pluggable – and in the last 3 apps I wrote (Storefront, Nerddinner, and SubSonic’s MVC Starter) I used my own ViewEngine to save some time and work. I’ve spun up my own ControllerFactory so I can use IoC (which is awesome fun!) Understanding this is the keys to the kingdom for any developer! Have you ever been freaked out because you needed to use Page_PreRender to get something to load into the ControlTree properly so it will show when you need it to? MVC does not lock you into anything – you’re free to do what you want to.
4 – It Makes You Think… This is the one thing I never liked about WebForms – I never felt like I was thinking – just solving. May seem like splitting hairs, but not to me. I’d get a bit of inspiration and then try to figure out “hmmm – how can I make the form show it this way”. MVC is the opposite – the control is in your hands and you get to be free with it. You get to use your noggin! Wow!
6 – Learning New Concepts. You’ve seen them everywhere, and seen us fighting about them. We probably shouldn’t argue so much but in a way, this is part of the learning process! Either way – take it upon yourself to learn some things. WebForms is a comfy blanket that can lull you to sleep over time. This has happened to a lot of us (myself included). We’re only now catching up with frameworks that have been creating rocking, compelling sites over the last few years – jog your brain! Wake yourself up and get to know the details that make compelling sites groovy! Learn the things that can help you write more nimble code – if only so you can argue from a point of knowledge!
7 – It’s Fun. This, to me, is the biggest reason. I find MVC fun because I can do what I want, when I want, how I want. I’m free to build an experience that I feel will sell my design, and I’m not hindered by a A Big Lie and a freaky cat with a wig on.
Bottom line: I’m having fun web programming again and I think that’s pretty motivating, at least for me and my cats. Yet Another Comparison, sure, but hopefully a bit more direct. You have absolutely no reason at all to not learn MVC – but I will concede there may be a reason or two for you to stick with WebForms.
I know many people might think I’m speaking for the rest of Microsoft – hardly. I’m biased and, more importantly, I actually still have my very own brain which forms its own thoughts! I love MVC and I think you will too – just please, please try it before you form an opinion.