Saturday, November 27, 2010

Who Should Use ASP.NET MVC?

As with any new technology, its mere existence isn’t a good reason for adopting it (despite the natural tendencies of software developers). Let’s consider how the MVC Framework compares with its most obvious alternatives.

Comparisons with ASP.NET Web Forms
You’ve already heard about the weaknesses and limitations in traditional ASP.NET Web Forms from my previous post, and how ASP.NET MVC overcomes many of those problems. That doesn’t mean that Web Forms is dead, though; Microsoft is keen to remind everyone that the two platforms go forward side by side, equally supported, and both are subject to active, ongoing development.

In many ways, your choice between the two is a matter of development philosophy.

• Web Forms takes the view that UIs should be stateful, and to that end adds a
sophisticated abstraction layer on top of HTTP and HTML, using ViewState and
postbacks to create the effect of statefulness. This makes it suitable for drag-anddrop
Windows Forms–style development, in which you pull UI widgets onto a
canvas and fill in code for their event handlers.

• MVC embraces HTTP’s true stateless nature, working with it rather than fighting
against it. It requires you to understand how web applications actually work; but
given that understanding, it provides a simple, powerful, and modern approach to
writing web applications with tidy code that’s easier to extend and maintain over
time, free of bizarre complications and painful limitations.

There are certainly cases where Web Forms is at least as good as, and probably better than, MVC.
The obvious example is small, intranet-type applications that are largely about binding grids directly to database tables or stepping users through a wizard. Since you don’t need to worry about the bandwidth issues that come with ViewState, don’t need to be concerned with search engine optimization, and aren't bothered about unit testing or long-term maintenance, Web Forms’ drag-and-drop development strengths outweigh its weaknesses. On the other hand, if you’re writing applications for the public Internet, or larger intranet applications (e.g., more than a few person-month’s work), you’ll be aiming for fast download speeds and cross-browser compatibility, built with higher-quality, well-architected code suitable for automated
testing, in which case MVC will deliver significant advantages for you.

No comments:

Post a Comment