Archive

Posts Tagged ‘MVC’

The need for JavaScript “Frameworks”

This title seems relatively understandable, but I assure you I don’t mean libraries like, JQueries, Dojo, or YUI..  Quite on the contrary. The difference between frameworks and libraries is the pivotal point.

Libraries vs Frameworks

Libraries simply provide functionality. For example, JQuery is an awesome library. It can enhance any website adding interactivity with minimalistic and efficient code. When people think of frameworks on the other hand. Things such as Django and Rails come to mind. The difference might be coming more clear now.

Most importantly, frameworks provide an MVC structure to work on. They provide a structured approach to getting to job done. Good framework will keep your code clean and actually give you less that will “just work” better.

Web application developers generally neglect the use of MVC in highly dynamic web pages when they really shouldn’t. To be specific I believe that the Model (M in MVC) is ignored quite too often.

JavaScript does have frameworks, quite a few in fact, with some of the most notable being SproutCore, Cappuccino, and JavaScriptMVC.  Far too often they are unheard of or unused.  From what I’ve seen it’s simply the complexity level and browser support (slow JavaScript) that really keeps people away.  But as those tides turn it’s time to re-think our front end strategy.

The real divide

Here’s what I suggest all good web apps should look like.  A two-tiered approach.

Front-end MVC

The part of the MVC that gets trampled the most in front-end coding has got to the the Model.  Without it, data has no form of encapsulation and becomes a big pile of variables.  It’s hard to find cohesion between data-sets and the front end becomes complicated to understand.  Models also make it easy to cache previously used data.

Views seem harder to picture but it would be the currently visible portion of the web page.  Currently active and running widgets would account for the View here as well.  Anything dealing with or CRUDing (Create, Read, Update, Delete) HTML.

If you can segregate your JavaScript into logical Models and Views then Controllers will naturally be responsible for handling the actions and events.  And JavaScript is really good with that stuff :)

Cleaner Code Ahead!

Always think of web applications as two separate tiers (which they are!) and you will realize that the browser deserves good object design as well.

http://cappuccino.org/