Scott Hanselman - Last night at Microsoft

Being on the southern tip of the world—and with the slowest bandwidth anywhere (confirmed by Scott himself)—we seldom get the greats like Scott Hanselman out to talk to us, let alone for free, and when he is on holiday… but that’s what the S.A. Developer community got last night, and what a night it was! He spoke last night on MVC, and I made some notes I thought I would share.

The first concept is that:

It’s an interesting way of thinking that ASP.NET isn’t just Web Forms, since we normally use those two terms interchangeably. ASP.NET is a framework for building web applications; if we use Web Forms on that framework, it’s a choice, not a requirement. Web Forms, in itself, is a lie—it tries to make us believe the web is stateful, so we get the RAD/VB6 experience for development. The problem? Like the Matrix, the lie constrains us. MVC, in a way, is the anti-RAD: it opens up far more to the developer than Web Forms traditionally does. Knowing there’s a lie—and knowing the truth—can hurt (the same way Neo knew there was no gravity, yet fell). And so MVC can hurt you. MVC is not a replacement for Web Forms; it’s another way to solve a set of problems. Some problems are better solved in Web Forms, while others fit MVC (or ASP.NET Dynamic Data) better.

MVC is made up of models, views, and controllers—and all of these are changeable. The views use Web Forms to render HTML, but other options exist. One is NHaml, a very different way to generate HTML (you can read about it here). Views should contain no logic—they should focus solely on rendering HTML. What’s nice is that, for the rendering side, jQuery is bundled directly into MVC!

Separate from the views are the controllers, which leverage ASP.NET’s Routing feature (introduced in 3.5 SP1) heavily. Its implementation is elegant, showcasing a "convention over configuration" approach. For example, if you type a URL like http://test/account/view, it first checks the Views\Account folder for View.aspx or .ascx, then the Views\Shared folder. No config is needed to map the URL to a file. Controllers should hold most of the logic but avoid web-specific concepts (like the Request object). You could use it, but that breaks MVC’s separation of concerns. The beauty of MVC’s design is that it enforces separation, making unit testing astonishingly simple. With the full version of Visual Studio, it even generates unit tests for you! While it’s easy to add authentication checks in a controller, you must decide how much "code smell" you can tolerate.

Still separate are the models, which represent your data (e.g., LINQ to SQL). The purest form of MVC involves a data model and a model to interact with controllers—keeping them distinct. In the real world, that separation doesn’t always pay off, but because you have the power (you took the red pill), you can share models between the data layer and controllers.

Afterward, Scott showcased his latest project: NerdDinner, an MVC-based app set to become an open-source solution on CodePlex. He walked through the code, highlighting both strengths and pitfalls, making it clear what MVC challenges—and rewards—look like. The session wrapped up with Q&A over pizza.

Definitely one of the best talks I’ve attended in a long time! And here’s a bonus: Scott’s on his way to Cape Town—taking a day out of his holiday to fly in specially—so if you’re in CT, you must go see him! Check S.A. Developer for details.