I <3 MVC, even though that doesn't mean anything to most people

posted by Jeff | Friday, March 27, 2009, 11:55 PM | comments: 0

While at Mix, Microsoft finally released the ASP.NET MVC framework. It had been in development, openly, by the way, for more than a year. I thought it was interesting enough, but just didn't feel inclined to get into it as it was changing for much of the year.

Then it went final, and I thought I'd start playing with it. MVC stands for "model-view-controller," a design pattern that has been around for a very, very long time. Basically what it means is that you build an app so that the three components can do what they do without having to know much about each other, and you can test them all independently. Other Web platforms have had this for some time, the most famous of which is probably Ruby on Rails (which you've likely used in many of these "Web 2.0" apps). It's interesting and important because it takes a ton of grunt work out of getting data in and out of a Web application.

ASP.NET "Webforms," the old standard, has its roots in the way people used to develop Windows applications. You'd declare a bunch of controls like text boxes and buttons and then write a bunch of code to handle the events around them and do stuff. That's a little cumbersome on the Web, since the server doesn't typically know anything about what your Web browser's state is. It's powerful, sure, but developing stuff can be a little slow going, and you end up writing a lot of code over and over.

But MVC, along with some newer data frameworks in the Microsoft world, remove all of that overhead and get you to the meat of what you want to do. Figuring that I need real examples to learn something, I decided to make a little blog engine, since I'll eventually be migrating off of CampusFish. Sure, there are a bazillion existing free apps, including MS's Oxite project using MVC, but I wanted to learn for myself.

So here's how it's going. Not counting the generated code for data access, I've written a little over 200 lines of code. I can create and edit blog entries, display them, get lists of them, create and edit users, and handle logins and outs. In barely 200 lines of code!

This is making programming fun again, in part because I can already see how easy it is to concentrate on the user interface and design. I still have to get used to some of the quirks and buckle down a little to get the true benefit of testing, but it's still very exciting.

End geek nonsense. For now.


Comments


Post your comment: