There’s a new video up on www.asp.net which aims to help developers pick between ASP.NET WebForms and ASP.NET MVC. The video boils down to 5 benefits per technology which Microsoft thinks you should consider.
Let’s go over the points, shall we? First, ASP.NET WebForms:
1 – Familiar control and event base programming model
The claim here is that the ASP.NET model is comfortable for WinForm programmers (thankfully this unbiased analysis left out who it’s more familiar for). This is largely accurate, but disingenuous. The differences between web and desktop cannot be overstated nor can one overstate how bad ASP.NET’s (or any other framework) is at hiding the difference. “Familiar” is probably the right word to use so long as you recognize that, in this case, at best it means: superficial; at worst: a serious pain in the ass. Your knowledge of building a VB6 app will allow you to write a “Hello World” web application – great.
Familiarity can be a liability when it tries to force a square peg into a round hole.
It also largely relies on your inability (or unwillingness) to learn. Today, next month or even next year may not be the right time for you to learn something new – that’s fine. Eventually, sticking with what you know, only because you know it, will kill your career and possibility part of your spirit.
2 – Controls encapsulate HTML, JS and CSS
3 – Rich UI controls included – datagrids, charts, AJAX.
Point 3 is a different perspective on point 2, which is a different way of saying point 1. However, it is the most interesting and important perspective. Fancy tables and charts, as well as client-side behavior, shouldn’t be a server-side concern. This is fundamental to what we all know about good and bad design. Classic ASP was a mess because it intermingled presentation code with server side code. The value of WebForms is that presentation logic is now a server side concern. Do you really believe this? Would you consider generating your HTML from a stored procedure?
4 – Browser differences handled for you
I’m guessing that the claim is that some of the controls mentioned in point 3 might render different HTML based on the requesting browser. Guess what, most jQuery (or any other js framework) plug-ins are fully compatible with all relevant browsers because they too can generate different HTML. In fact, doing this on the client side is almost always better – since you can tell the exact capabilities of a browser.
Also, it would probably be better if you generated correct HTML, CSS and JS in the first place – something you can’t normally control using ASP.NET WebForms. So not only is this really just a benefit because IE is a pain, but its only worth mentioning because points #1, #2 and #3 mean that you’ve lost complete control over doing it right in the first place.
5 – SharePoint builds on WebForms
Yes, if you use SharePoint, you’ll have to use WebForms.
Now on to ASP.NET MVC:
1 – Feels comfortable for many traditional web developers
ASP.NET WebForms is familiar while ASP.NET MVC is comfortable – that’s helpful. Nonetheless, when I see “traditional” I think “not-modern”. A more honest counterpoint to the WebForms claim would be: “A more natural way to build web applications”. WebForms tried to help WinForm developer’s transition to the web. ASP.NET MVC is a model that better reflect the realities of programming on the web. It’s more than just comfort, and has nothing to do with tradition.
2 – Total control of HTML markup
HTML, JS and CSS are yours to command. That doesn’t mean you can’t use controls to speed up development and improve your applications. The way this is worded sure makes it sound like MVC is a lot more work than WebForms though. It isn’t.
3 – Supports Unit Testing, TDD and Agile methodologies
I’m not sure what the technology stack has to do with the development methodology, so we’ll just ignore the last part. That aside, its true that MVC makes it possible to unit test your code. The counter point to that is that WebForms is essentially impossible to unit test. This also understates the architectural superiority and design of MVC – its doesn’t only allow you to leverage a number of best practices, it itself is actually built around those same practices. Code that can be unit tested, regardless of whether it is or not, is almost always superior to code that cannot.
4 – Encourages more prescriptive applications
So if ASP.NET MVC lets you build you application the way you should be building it, should you infer that ASP.NET WebForm forces you to build applications the wrong way? Yes, you should.
5 – Extremely flexible and extensible
Both frameworks share this value – but ASP.NET MVC is more about building on top of existing code, while ASP.NET WebForms is more about hacking things until they work. If you think this means that ASP.NET MVC can only be useful once you’ve extended it, then you are wrong. It works great out of the box is is feature rich.
The video goes on to make weird assertions, like the possibility of turning back and picking a different stack if you feel you’ve made the wrong choice because of how similar and how much infrastructure they share. The better solution is to pick the right technology because going back months or years into your project doesn’t sound like good advice to me.
It also mentions that it’s common to have some pages handled by MVC and others by WebForms. It’s good to know that you can do this – especially since it’s a good way to upgrade from WebForms to MVC. However, I’d hardly call it common or even recommended. It’s a useful transitional tool which you should aim to get out of as quickly as possible.
Ultimately, the first 4 values of WebForms all boil down to the same thing: there’s a
System.Web.UI namespace which represents the wrong way to build a web app. There are good reasons to pick WebForms – but they all come down to time and practicalities of learning new things (and SharePoint). I won’t tell you that you have to learn MVC, because that may not be practical for you. I’ll repeat what I’ve said before, ASP.NET MVC and WebForms DO NOT serve different purposes and one is not better suited for a particular type of application than the other(except SharePoint). They are completely overlapping technologies, and ASP.NET MVC is superior to WebForms.