MVC vs. WebForms, A Clear Loser Emerging
Working with WebControls and WebForms for the past 8 years has taught me a lot about web development. The one thing that I learned above everything is that the onus is on the developer to write good code. Now that may not sound like something revolutionary, but the fact is that ASP.NET WebForms makes building web applications easy by abstracting away some of the difficulties of a stateless protocol. And it also makes it easy to forget about what’s actually happening behind the scenes to make everything possible. Does that mean WebForms is flawed? No.
MVC offers a fix for some of the problems that WebForms has been plagued with. Problems like bloated ViewState, and that ‘pesky postback model.’ On the surface, this looks like an attractive solution for every web developer out there. A promise to get rid of ViewState – a web application’s mortal enemy? It has to be good. That is until the application your building needs some sort of state mechanism, and you begin re-inventing the wheel. I think it would have been much easier just to go back to you WebForms application and disable ViewState.
The problem right now is that there is so much focus over why MVC is better than WebForms, that everyone is forgetting a basic rule of software development: use the right tool for the job. I’ve said it dozens of times, MVC has a set of scenarios that it first very nicely, as does WebForms. One platform does not need to be declared a winner – they’re two equals that should be placed into your metaphorical toolbox. So who is actually losing right now? The developer community that is caught in the middle of this faux war. Developers who think that they have to move to MVC out of pride or fear that WebForms will be replaced by MVC. Developers who are only hearing one side of the story right now at local community events and tradeshows because let’s face it.. WebForms isn’t sexy anymore at 8 years old. Ironically, this same issue of “sexy talks” was discussed last week at NDC with Scott Hanselman behind the camera.
Conferences aren’t picking talks about “the old stuff”, because they’d rather focus on what’s new. New is sexier, and conferences are all about attendance numbers. But here’s what these conferences don’t seem to understand – every day there’s a new developer joining the community who needs to start from zero. Developers gauge what’s important by what’s being talked about, it’s why we have trends and tag clouds. It’s human nature. If I hear 100 people talking about a subject, it must be important. Right now I hear 100 people talking about MVC, and no one talking about WebForms, so I guess MVC is more important, right? That’s the type of thinking happening right now, and it’s nothing new.
“MVC brings web development back into ASP.NET”, is one of the most common arguments I hear for its use. Yet the whole reason for WebForms existence was to free you of the dirty details of building a web application, and let you focus on your business logic. To give you a set of functionality to be able to build on top of, the same focus for every library and framework out there. It’s why you don’t have to write browser specific JavaScript when using jQuery or ASP.NET AJAX, and it’s the reason we don’t still program in machine language. Can I write a tighter loop in assembly than I can in JavaScript? Sure. But for the applications I’m writing that’s not going to be an issue. Maybe I’m writing an application where performance is the top and only concern. Now writing the application in assembly doesn’t sound like a crazy idea. If my requirements were to build a spreadsheet like application that offers filtering, copy and paste and exporting to excel, I’m going to jump to WebForms. That’s the whole point behind using the right tools for the job.
I read a blog post today that talked about how you should dump WebForms and go with MVC as soon as possible, so you can get back to web development roots. The argument just didn’t make sense to me. It’s like asking me to stop coding in C# and move to C++ because C# developers just don’t understand pointers and memory allocation.
So here’s my call to action. Rather than talking about why one framework or platform is better than the other, start discussing when one is better than the other. What scenarios is MVC geared for? When would you use WebForms (MVP) instead?
The best advice I’ve seen so far is that WebForms is the platform of choice for building web applications, where MVC is more suited to building web sites. This is still a bit abstract since there’s no clear definition of web applications, but I think it’s safe to say that if you’re building a web version of a win client application, you’re building a web application. If you have a ‘grid’ in your page for purposes above that of just layout, you’re building a web application.