ASP.NET MVC vs ASP.NET Web Forms

   I have been playing with ASP.NET MVC these days and I am ready to share my impressions with the countless readers of this no-blog. I have seen several presentations comparing ASP.NET Web Forms with ASP.NET MVC and they inevitably start with the presenter slipping out of any responsibility and telling the audience that he cannot tell them what to use. Well, these presenters are pussies. While I will not take any responsibility when your project fails I can tell you which one you should choose. Just take this simple quiz.

   How to use the quiz? Look at the suggested statements and rate them with points from 0 to 10 based on how likely you are to make them. Note that the given examples are the extremes. You can be anywhere in between so you can rate any pair of statements with any number from 0 to 10.

0.
I have read the HTML standards; I care about valid, semantic HTML. + 10

I just want the site to work; I do not care about bullshit standards that nobody follows anyway. I do not know what "semantic HTML" means (did you just made this up?) and I am OK with all kind of crap in my HTML because I do not look at it. + 0

1.
We have dedicated designer working on the project and changing markup in the process of development. +10

Designers are annoying and they know nothing about programming. That is why we fired our designer, had the client draw what he wants on a piece of paper and one of our developers who knows some CSS is recreating it. +0

2.
I have programmed web only. I like programming stateless, RESTful, web-style stuff. + 10

I have programmed desktop for years, the majority of my job is desktop, I like drag & drop designers, I want my program to have state and I hate the Web. + 0

3.
I know about design patterns. "Dependency Injection", "mocking" and other similar words do not sound scary to me and I believe they always make my code better so I am always trying to use them. + 10

I think that design patters are a waste of time, they are overrated and I am not willing to invert my controls because I think this will switch the direction of the Y-axis of my mouse. + 0

4.
I am disciplined enough or my boss can make me write a lot of unit tests. I have done test driven development; I love to automatically catch errors when making changes. + 10

I think unit tests just waste time and are generally useless because they cannot catch all bugs anyway. I find them boring to write and I would rather quit than listen to my boss if he tells me to write them. How can he know about modern programming if he works mostly in Word and Outlook these days? +0

5.
My project is an internal app or an app that I will have to support for decades. The deadline is "when it is done". +10

I have severe deadlines to meet. I will be paying damages if the project is not out of the door on time and support is not included in the price (HAHA!). +0

6.
I believe that the Web is the future of programming and web applications will eventually conquer the world. The browsers will have 100% standards support real soon and everything will be fine. +10

I believe that the Web is a piece of shit and soon everyone will find out the truth and will switch back to desktop apps or RIA. Those browser vendors will never reach agreement on the standards and legacy markup has fucked everything up. It is like Gaza - there cannot be peace. Ever! +0

7.
My project is BIG. +10

My project is small. +0

8.
Everyone on the project is highly skilled professional. They like to do things the right way, they like to be in control and they do not abuse technologies and patterns. +10

Everyone on the project but me is an idiot. And I am not even sure about myself. We abuse patterns and technologies and write sucky code all the time. +0

9.
I want maximum efficiency when creating AJAX stuff and I am willing to write some HTML and JavaScript by hand to achieve it. +10

This AJAX bullshit is already causing problems. I do not want to write JavaScript by hand and deal with the problems of all the browsers. It is not a big deal if there is some extra network load if everything works automagically. +0


I want to use XHTML. - You should not do Web development at all but if you are going to do it anyway. -10 (this is MINUS ten)

   If you got more than 55 points you should use MVC otherwise you should use Web Forms. In order for the quiz to work you have to be honest and also you need good judgment on your team skills and the requirements of the project. Maybe with time I will tweak the importance of different points in the quiz. The closer you are to 55 points the less dangerous the choice is. You will probably do equally well or bad with both technologies.

   If you paid attention to the quiz you should already know my opinion on MVC. In the perfect world MVC would be better than Web Forms. However we do not live in the perfect world and we can get really deep in the shit if we do not use MVC as it is supposed to be used. Of course one can abuse Web Forms too but the damage seems to be much more contained. Let me explain every point in the quiz

0.  With ASP.NET MVC you have full control over the markup but if you are not an expert in good markup what good is this for you? You have better let Web Forms generate the HTML for you because chances are that it is better than what you can write.

1. You can take static HTML and mix in server side code easier with MVC. Otherwise you have to replace tables with Grids, inputs with TextBoxes and so on. And when the designer changes something…

2. State is hard to maintain in the Web. You will have to work around the issues yourself if you let go of Web Forms' page model. If you do not have experience programming in stateless environment this may prove to be hard.

3. To make full use of MVC you need to know some patterns. You will not get many benefits just from creating the project as an MVC App. You need to learn to use it. On the contrary just by creating Web Forms project you will get at least some benefits. Web Forms seems to be somewhat easier.

4. Unit tests are one of the main benefits of MVC. If you do not write tests it loses much of its appeal and most developers do not like writing tests. On the other hand Web Forms is harder to test if you want to.

5. MVC is much better for maintenance as it enforces cleaner separation of concerns. However doing it right takes time. Developing Web Forms seems to be faster. Note that MVC is not very slow and Web Forms is not unmaintainable. It is just a matter of what they focus on.

6. MVC is much closer to the way the Web works. It is down to the metal. However if you want to have full control you have to deal with all the problems.

7. Big projects need more maintenance and better separation of concerns. It is OK to change something in two places but it is a pain to change it in twenty. Small projects are also easier to test manually when you make a change.

8. If you do not use MVC the right way you are going to sink much faster than with Web Forms or at least it looks so to me. Of course this does not mean that the amount of crap that Web Forms can take is unlimited.

9. AJAX is harder but much more efficient with MVC. You can transfer over the network only what is needed. With AJAX.NET in Web Forms you post the whole form and get back some HTML plus the View State but you can AJAX-ify existing application in minutes. It does not require knowledge of JavaScript. Note that you can write totally efficient AJAX with Web Forms but it requires more work than with MVC.

   The reason I picked 55 and not 50 for the result of the quiz is the existing know-how, premade controls and the maturity of tools for Web Forms. Example of immaturity of the MVC tools is the fact that you get JavaScript errors in Visual Studio when you try to embed server side values in the script. Once again I would like to point out that any project can succeed or fail with any of these technologies. It is just a matter of which is more suitable.
Tags:   english tech 
Posted by:   Stilgar
16:16 06.04.2009

Comments:

First Previous 1 Next Last 

Posted by   Ravenheart   on   00:00 08.04.2009

I got 8 points, WebForms ftw I guess for me :)

Posted by   JOKe (Unregistered)   on   01:37 10.04.2009

realno kyv e targeta na tva MVC ?

Posted by   Gerry (Unregistered)   on   20:35 24.05.2010

I got 22, down with MVC

Posted by   Guest (Unregistered)   on   15:46 05.03.2011

In my opinion, the question is becoming blurred with a lot of the cool features of MVC making their way into Webforms.  ASP.NET 4.0 added URL Routing, reduced ViewState, and greater control of the HTML mark-up produced by many ASP.NET controls, now the next version of Webforms will incorporate many more MVC features into Webforms.  http://bit.ly/dNhBd8

Posted by   Stilgar   on   21:22 05.03.2011

The improvements in Web Forms do not provide more control over the markup (well there is the ID thing but it is small) but make the rendered markup much better. The idea behind the control model is that the markup is handled for you therefore you give up control of it. Which is good. The problem is that the default controls often render bad markup.

First Previous 1 Next Last 


Post as:



Post a comment: