Thursday, October 11, 2007

New Asp.Net MVC Framework

At the recently-concluded Alt.Net conference, ScottGu demoed a new pre-pre-alpha MVC framework for Asp.Net. The presentation is definitely worth a look.

This is a great example of why Rails is such a good thing even for those of us who don't get to use it professionally. Something as subversive as Rails is bound to have wide-reaching effects far beyond the actual framework. It's already motivated MVC frameworks in just about every language imaginable - including the open source MonoRail implementation built on top of Asp.Net.

Microsoft seems to be consistently a few years behind the state of the art (in unit testing, ajax, mvc web frameworks, etc.) and they have this irresistible urge to write their own versions of perfectly good open-source tools. But at least they realize a good idea when they see one. The next version of the .Net framework has some really exciting new features like extension methods and lambda expressions, which make them look almost (dare I say it) as clean as Ruby blocks.

Some scattered thoughts from the presentation:

  • The whole talk was giving me Rails flashbacks. All the terminology seemed to be borrowed from rails, as was the default routing format. Visual Studio was even set up with a dark color scheme  that evoked the popular textmate theme.
  • Routing uses a tokenized-string format. I like the syntax: it's very intuitive and clean. But Scott mentioned that an earlier version used Regular Expressions, and that was changed because they found that, while Regular Expressions are super-powerful, only like 10% of people actually understand them (~10:30 in the video). This shows some of the self-imposed constraints Microsoft is working under. No Regular Expressions because they are too hard to understand?

    This mentality is, I think, the source of most of the problems with Asp.Net in the first place. The drive to make web programming "just like" windows programming and cater to the lowest common denominator is behind some of asp.net's worst features: The page lifecycle. and viewstate(love it/hate it) are the two biggest offenders, IMHO. Getting closer to the html and http metal means knowing more about them, yes, but it also makes the framework vastly simpler. You won't get an OnChange event on your texboxes. But I'll bet that the time you save learning about html and http is spent debugging page lifecycle issues or figuring out that you need to use Control.UniqueID instead of Control.ClientID.
  • Scott emphasized many times that the entire architecture was designed to be very pluggable (don't like it? change it!) and easily unit-testable. There will be support for mock objects using common frameworks (Rhino mocks/Typemock were mentioned by name). Very cool.
  • The community seems to be very excited about this. You can see a lot of enthusiasm, both in the audience for Scott's talk and in the comments to this blog post. You can also tell what (this part of) the community cares about. Scott fielded a lot of "is that class sealed?" questions (to which his answer was always no), and lots of people seem to be happy about getting rid of the postback model.
  • Along with all the extensibility points that Scott mentioned, he gave some specific examples of alternate implementations that could be plugged in. At just about ever point, there was a Castle/Monorail alternative that could be used. It left me wondering, if you plug in all the Monorail components, how much of the MS framework would be left? Doesn't seem like much.
  • Model classes take a hash, just like in Rails, so that you can update them directly from form parameters: Customer.UpdateFrom(Request.Form).
  • The framework will ship with a bunch of MVC-specific controls, but many of the standard ones (the Repeater was mentioned by name) apparently do not require webforms and can be used as-is. Master pages and user controls can also be used.
  • The first public release should be in 6-8 weeks, with a final release in spring 2008.

No comments: