Ever since ASP.NET MVC was announced/released, there’s been a lot of talk about it with respect to ASP.NET WebForms. People want to know which technology they should use, and are likely confused by the fact that there isn’t a consensus amongst respected developers with respect to which of the two is better.
Ideally every developer would take the time to truly understand ASP.NET MVC and compare that with their WebForms experience to come up with their own opion (and even more ideally we’d all largely agree on the pros and cons). The reality though is that some developers don’t have the time or opportunity to take the necessary time to learn a new framework. If we are being completely honest, many developers don’t have the necessary skill to accurately judge two competing technologies – maybe they are casual developers, maybe they are new to developing; maybe they come from a different technology. There’s nothing shameful about that – in fact, that’s how most of us learn.
With that said, should you be using ASP.NET MVC instead of WebForms? The short is: continue using WebForms for any existing projects that you have that are working well (you can define for yourself what “working well” means). Use ASP.NET MVC for any other project.
The long answer is the same, except it uses the word “stupid” and “idiots” a lot more. Here goes…
So-called experts who claim that ASP.NET MVC and WebForms serve two different purposes are stupid idiots. Seriously. They are both web frameworks, capable of producing the exact same systems. You could build a digg, facebook, twitter, joomla or any other website using either technology. What makes one (ASP.NET MVC) better than the other (ASP.NET WebForms) isn’t where you can go, but rather how you get there. ASP.NET WebForms is an ugly and messy framework that complicates an otherwise simple thing. ViewState, codebehind, postback, page lifecycle and databinding are things that you have to constantly program against. They don’t help you; they just slow you down, slow your site down, and make it harder to change things in the future.
I’ve known programmers who thought that complex frameworks were required to build complex systems. I also know programmers who think you can just duct tape anything together. The truth is so much simpler, and so much better, that both those groups of programmers are idiots, and in fact can’t really program. Simplicity is the only way to build simple or complex systems in a clean and timely manner. Build a system too complex, and it’ll cost a fortune and be too rigid. Build something too quickly and shitty, and it’ll break and won’t be fixable. ASP.NET WebForms, along with ASP.NET Ajax, was clearly built by people who believe that complexity can solve all problems. Postback with server side events is such a poor solution to what’s a really simple problem. ViewState is a solution to a problem that doesn’t even exist (which makes it infinitely complex).
Pro-WebFormers like to use a scare tactic to make sure developers don’t switch to ASP.NET MVC, they claim that ASP.NET MVC is suited for Test Driven Developer (TDD) specifically, and unit testing in general. This is a scare tactic that relies on the growing divide between those who do and those who don’t unit tests. You can use ASP.NET MVC without writing a single unit tests, or knowing how to write a unit test, or knowing what a unit test is. It is true that ASP.NET MVC is easier to unit test than ASP.NET WebForms (which is next to impossible). Even if you don’t write unit tests, or know how to write unit tests, or know what a unit test is, believe me that the simple fact that ASP.NET MVC can be unit tested and WebForms can’t, is a very compelling reason to forget about WebForms. It means that ASP.NET MVC is better designed, is more flexible, has less coupling, and less magic shit which will break.
If someone tells you that ASP.NET MVC is more complicated, requires more heavy lifting or is less productive, they are trying to tell you a lie. Of course there’ll be the lost productivity of having to learn something new. But I promise you that mastering ASP.NET MVC will take a fraction of the time its taken you to master the clusterfuck known as ASP.NET WebForms (just like learning jQuery will take you less time than learning ASP.NET Ajax). Maybe you don’t have time to learn something new, that’s fine. Just don’t believe what you’ve been reading. ASP.NET MVC is simpler – unless you’re the type of developer who doesn’t like to learn new things.
Now, I have my problems with ASP.NET MVC, which I’ve shared in the past. But those are problems with ASP.NET MVC with respect to other MVC frameworks.
A framework that accepts that HTTP is stateless will always be simpler, cleaner and more powerful that a framework that doesn’t. A framework that allows unit testing, regardless of whehter you are going to unit tests, is better than one that doesn’t. WebForms is nasty.