Styles

Tuesday, November 29, 2011

ASP.NET WebForms vs. ASP.NET MVC


When .NET came out in the early 2000s, Microsoft replaced Active Server Pages with ASP.NET WebForms.  That was the preferred approach to web development in the Microsoft world until recently, when ASP.NET MVC came out.  (Silverlight is also an option, but I view that as a way to beautify an existing site, not act as the foundation for one.)  There is a lot of material out there that describes the difference between these platforms, but almost none of it is targeted for the high level business executive in technology, such as the CTO.  So here is my attempt at outlining the differences without getting into too much technical jargon:

ASP.NET WebForms
WebForms are by far the oldest technology in the Microsoft web stack still actively used today.  (No, I wouldn't consider ASP as still actively being used today.)  The framework was originally created to help WinForms developers write programs for the web without needing to learn about some of the peculiarities of web development.  While Microsoft cannot hide from these peculiarities completely, the framework made some tasks a lot easier.  Unfortunately, in order to make this happen, the creators of ASP.NET WebForms needed to send a lot of information to the browser, leading to potentially very large (therefore slow) pages as well as making highly interactive web sites more difficult.

ASP.NET MVC
Programmers eventually found some of the tools that WebForms provided cumbersome and awkward, so Microsoft came out with a leaner framework in the form of ASP.NET MVC.  The benefits were that MVC makes it easier to write JavaScript, saving trips to the server and improving the overall user experience.  The drawback is that the MVC developer needs to do some of the work that WebForms would do automatically.

Which one is better?  That, of course, depends on your circumstances.  Here are some pros and cons:

WebForms pros
  • Good for getting something up and running quickly
  • Easy to understand for WinForms developers
  • Even in the hands of someone only marginally competent, code can still be understandable
  • Relatively easy to create pages with a lot of functionality without making the HTML too confusing for the developers
WebForms cons
  • A lot of HTML gets generated that slows down the browser and gets in the way of AJAX requests
  • A lot of code in inaccessible code-behinds can lead to more testing through the UI than should otherwise be necessary
  • Steep learning curve for those coming from other web programming languages
MVC pros
  • Clean HTML means faster load times and easier JavaScript/AJAX
  • More unit testable
  • Shallow learning curve for those coming from PHP or Ruby On Rails
  • Cleaner HTML leads to cleaner CSS
  • More easily integrates with third-party JavaScript and CSS tools
MVC cons
  • Can lead to unreadable code more easily than WebForms
  • Pages with complex functionality will have complex HTML for the developers
  • More tools/blogs/help available that focus on WebForms
In short, developer skill level aside, if you’re creating a highly-interactive site, MVC is the more natural tool.  If you’re creating a site with a lot of functionality on each page, WebForms is the more natural tool.  When in doubt, go with the tool that you or your developers are most comfortable with, unless you’re deliberately evaluating the other option.  There is nothing you can do in one format and not the other; there are just some things that are easier in one format or the other.  I personally prefer to work in MVC because of the cleanliness of the code that’s generated, but my bias is that I prefer to make my sites highly-interactive.

No comments:

Post a Comment