I’m a convert… Well, lets say I’m Converting
ASP.NET MVC. I know I’m not the first on this train. I don’t know why it took me so long… Ok, yes I do, and I’m going to tell you, in a longer than average anecdotal story about the problem: Ruby-on-Rails. People talk about Ruby like it’s the best thing since sliced Swiss cheese. And Rails, well that’s just grilled cheese sandwiches!
Some people talk that way, anyway. I realize that it may be developer-reputational suicide, but I have to come clean: either I’m not enough of a geek to appreciate it, or no, it’s not [the best thing since the proverbial sliced stuff.] Some of Ruby is great, in that it can do some things quickly with little ‘ceremonial preparation,’ but then again the syntax is so abrupt and boxy that it actually appears HARDER for me to read than C#. This is in complete contradiction to those who assert that Ruby is so nice that you don’t even have to comment it. (Because it’s so obvious what the code is doing just by looking!) Maybe I’m just afraid of change, or talking my book, but I’m not feeling Ruby, and Rails, (which was the quintessential example of the MVC pattern,) well they kinda left me with a less than sweet taste about the MVC concept.
I know what you’re thinking here, and you’re right. It’s not a fair leap to make from “Rails is not My Thing” to the “MVC Pattern Sucks.” I try to be rational, and reasonable, but clearly here I wasn’t. Sorry about that.
Now back to ASP.NET MVC. It’s the coolest thing since sliced ASP.NET.
The concept of MVC made sense to me. Inversion of Control, Separation of Concerns, Dependency Injection, convention over configuration, testability… even back from my Rails tribulations. But I still didn’t feel it. It was someone else’s sense making not mine.
So then I decided I’d try to learn this jQuery thing… and I started playing around with raw HTML pages, throwing some jQuery into them in script tag after tag, and suddenly it hit me… Handling updates client side was great, simple, and often light. If all I had to do was juggle CSS classes and read a few fields here and there, Post a single variable now and again, I didn’t need the whole ball of wax! But, using web forms, you don’t have much of a choice. It was not fun having to register client scripts every time with a control’s server generated client name to go with controls that used the INamingContainer model. I started using the CssClass attribute quite improperly to get a grip on elements that should just have been simple enough to grab by ID. And then finally, the last straw was when I ran into a string of ViewState validation errors. Now, if you’re using ViewState, fine, there is a good reason to want ASP.NET to validate it. But I wasn’t using it, and ViewState was just an incidental side effect of the fact that web forms hate people who are using JavaScript.
So now that I had developed a new passion for everything jQuery, from the flashy jQuery UI, to simple things, I had to find a way to keep feeding it. Such ‘fancy’ sounding things were kids play now, like automatically italicizing certain text artifacts for fun and profit, or making post backs nothing but a service call or two. Services, as it turned out, were very comparable to Controllers, and in fact, could be serviced just as easily by Controllers as they could by ‘real services.’ Models were already familiar — I know about the repository pattern, I’ve done that quite a lot, even before I’d ever heard of ASP.NET MVC or indeed even Ruby on Rails. So the only things left to ‘get’ were the fact that both the view and the model were to be instantiated by the controller and called and returned (respectively.) The idea wasn’t foreign to me, but it now suddenly clicked. “Wait! This works, and I don’t have to worry about some of the things I spent time worrying about before.” Not to mention that the integration with Visual Studio is great. Another big bonus was the URL structure was nicer.
It took me a bit to realize that I was supposed to write custom html helpers, or still better, encapsulate the helper stuff into the equivalent of a ViewModel class that will do the html helping it its own logic.
So, I realize there is nothing really profound or new I’ve been talking about here, but I just have been so moved by ASP.net MVC that I had to say something about it. I think I’ll try to stick with using it wherever I can. The One Complaint that I do have with it is that SharePoint doesn’t support it, and I support SharePoint. Oh well. I always knew SharePoint wasn’t perfect either.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.