garann means > totes profesh

a defunct web development blog

MVC in Javascript

Fri, 21 Aug 2009 17:10:51 +0000

Nothing against Ajaxian, but I don't usually look to them for pithy wisdom - mostly I look to them for clever jQuery plugins and stuff. However, the paragraph at the end of this post on MVC for Javascript sums up my feelings pretty well:

If you think that view source / semantic markup is a great feature of the Web platform, then this kind of world is a touch worrying, but major apps have been doing this for years.

Once I worked on this project with a lot of contractors from IBM, and they were the ones defining the architecture. They had a very literal approach to MVC. As in, every single link went through a controller. Home link? Ask the controller. About Us link? Ask the controller. I've implemented MVC in C# (back before they had the framework for it, which from what I gather is pretty cool) and had it be useful, don't get me wrong.

MVC to me is one of those FUD problems, though. Even the experts can't quite agree on how it should be implemented. Reminds me of the not-Agile-enough or not-semantic-enough debates that seem to eat up a lot of valuable time that would be better spent coding. This is why I want MVC to keep its white-gloved, mechanically precise fingers off my Javascript.

As far as I'm concerned, there is no good pattern except the one that is obvious. The one that makes you smack your head, exclaiming, "Of course!" because it is perfectly suited to your problem and its application is absolutely clear. I think of the Factory pattern as a good example. What it does and why you need it aren't up for debate. MVC, on the other hand, is subject to interpretation once you try to apply it to environments it didn't grow up in. Javascript is a language for manipulating CSS and HTML. Manipulating the View. There is no single, clear answer to the question of how to apply MVC to Javascript because MVC in Javascript doesn't answer a need. Forgive me because - again - MVC has been very useful to me in the past (on the backend), but in this context MVC is nothing more than a buzzword.