ASP.NET MVC v. Web Forms Debate - My View

It seems that the whole world (and Margate) is having its say on which is better - MVC or Web Forms. Scott Guthrie posted his views on technical debates in general, and then contributed his thoughts on MVC v. Web Forms. Ian Cooper has an interesting contribution to make to the debate too. Rob Conery (formerly of Microsoft) posted probably the most linked to opinion on the matter. (There - I've just added another link...) A lot of other blog posts around scream that MVC is better because its better. One even tries to posit the notion that some kind of score card approach can help you decide.

The truth is that I can't tell you which development framework is better for you. But I can tell you which one is potentially worse, and that's Web Forms.

My personal preference is to use MVC for any web development I do, or for which I am responsible. I manage a growing team of web developers, and we do things with MVC. Recently, I went through an exercise in trying to recruit an extra body to the team. I was looking for a mid-level ASP.NET C# developer. I hoped to find candidates who had a good solid understanding of the ASP.NET Web Forms paradigm, ideally with a reasonable understanding of MVC. As the search went on, I found myself continually surprised at the lack of understanding that Web Forms developers displayed in regard to web development in general. One of them admitted to me that they only became aware of Request.Files as a result of reading one of my articles the night before the interview. Most of them had only ever developed web applications with ASP.NET Web Forms.

The fact is that Web Forms is a hugely successful approach to Rapid Application Development, and anyone like me who moved from scripting everything using classic ASP to ASP.NET 2.0 in particular can hardly fail to be impressed the first time they drag a GridView and SqlDataSource control onto a page, select a few options from a design-time configuration wizard, and within a couple of minutes, get a table full of data, with paging, filtering and sorting without writing a line of code. Us oldies remember how long it used to take us to build all of that using VBScript intermixed with HTML. The thing with VBScript (or PHP, for that matter) is that you had to know HTML if you wanted your page to render correctly. You also had to understand what ASP did, and how it differed from Javascript or other client-side technologies. You had to know about Request and Response, GET and POST.

Web Forms does something that MVC doesn't - it hides most, if not all, of that "need to know". And that's why it's potentially worse for you.

Conery describes Web Forms as 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."

Of course, it doesn't have to be that way. Conery urges you to understand that the web is not stateful and involves things like HTML and HTTP. As his piece progresses, it seems to suggest that you need to learn MVC to be able to grasp this.

You don't.

As a Web Forms developer, there is no reason why you cannot get to grips with HTML, HTTP, CSS, Javascript, browsers, the DOM, the technologies underlying AJAX, the difference between server-side and client-side code and so on, and so on. You should understand why there is only one <form> element in ASP.NET Web Forms, and why you may see multiple forms in other technologies. You should appreciate that the <asp:Label> is the most abused "control" in the entire framework, and why. You should know why the Properties Window in Visual Studio leads you into temptation (unless shortcutting event handlers) and the role that IPostBackDataHandler plays in the scheme of things. And all that is just for starters.

Contrary to Conery, I won't castigate Web Forms or people who develop with them. I've met people who, for whatever reason, have to use Web Forms. Their employers are nowhere near ready or willing to move across to MVC at the moment. And that's not to suggest that moving to MVC is a natural progression in web development either. Many companies have a huge investment in Web Forms technology that they just simply aren't going to throw out - training, third party controls, experience and so on. Many companies don't buy into the whole Unit Test pitch behind MVC. Many companies simply don't test at all.

However, knowing the fundamentals behind web development as a discipline will make you a far better ASP.NET developer. And ultimately more marketable.

And when if the time comes, it will make learning MVC a lot easier, too.