Review: Yahoo Mojito gives server-side JavaScript a lift
Yahoo's open source framework combines YUI on the client, Node.js on the server, and excellent use of MVC design pattern
From the beginning, programming for the Web has been divided into different camps. In the browser, there was always just one language -- JavaScript -- that dominated. But on the server, there have been dozens of candidates: Java, C#, Perl, Python, and countless others invented by people who weren't happy with the other choices. If you toss databases into the mix, there are several variants of SQL running the major platforms. It's a mess that drives programmers nuts.
The confusion may be ending, and Yahoo's Mojito may be part of the solution. Yahoo built Mojito by taking the best ideas from the various server stacks and creating a framework in JavaScript on top of Node.js, a server-side tool that might be called a cult. You write your code for both the server and the client in JavaScript, and Mojito keeps it working smoothly. (If you use some of the NoSQL databases, you can program them in JavaScript too.)
[ Also on InfoWorld: Node.js tools: Server-side JavaScript comes of age | First look: Google Dart vs. JavaScript | Keep up with application development developments with the Fatal Exception blog and Developer World newsletter. ]
Node can be incredibly fast, but it achieves much of this speed by operating without a safety net. If your code locks up, the entire server locks up with it. The most cultish devotees feel that this can be dodged with careful coding. Mojito encourages this care by offering the well-understood paradigm of Model-View-Controller, or MVC. Splitting the code into small distinct parts that serve predetermined roles makes it less likely that you'll lock up the server. That's the theory, but of course nothing can stop a determined programmer.
Mojito's MVC structure emulates the ideas and design paradigms that emerged from other Web programming worlds. The Java server-side programmers are so devoted to frameworks like Struts that you could get yourself stabbed in a Java bar if you even hinted that MVC is not right for all things. The paradigm succeeded because it brought some order and roughly approximated the way that development teams are organized. The people who are good with visual design end up in charge of the View; the people who organize the data (often DBAs) create the Model; and the programmers handle the Controller that makes decisions about what the data can do (the business rules).
There aren't many details on how to exploit this, but structure is there for you to separate the code as you need. You have to be careful how you use the structure, and in the spirit of Node, you do the work on your own -- it's up to you to avoid any traps. A mojit on the server won't be able to manipulate a DIV on the client, for instance. It's worth noting that one recent project, Opa, promises to use the compiler to make automated decisions about where the code will run, but that level of hand-holding isn't provided here.
The Mojito framework is also designed to be smart about devices; to be more precise, it's designed to help you deliver different code to different devices. If your website visitor is using a smartphone, for example, the framework can dispense a different View built with a different template and a different set of local functions. This device sensitivity is essential these days, and the Mojito team was smart to build it into the framework itself.
There are still some limitations. I wish Mojito had some coupling with databases because that's what many developers are going to want to do. Node frameworks such as RailwayJS and Locomotive offer Rails-like connections to traditional databases. If you want a quick CRUD scaffolding to create, update, or delete rows in the database, one command can build them for you.
The Yahoo team should forge a tighter alliance with the major NoSQL databases that speak JSON and JavaScript already. MongoDB, for instance, which takes queries in the form of JavaScript functions, is a natural partner. A difficult question is whether there also needs to be better integration with MySQL and other traditional databases. These continue to have strong followings, and if Mojito wants to gain access to shops with legacy SQL databases, the project will have to consider tighter integration. Or maybe they'll just insist that the legacy stores start answering RESTful queries with proper JSON.
Will Mojito succeed? The speed of Node will continue to attract new experimenters who quickly discover they can't build an entire Web application in one file as many of the hard-core Node lovers do in their early demos. As soon as they discover that raw Node programming can produce inscrutable code that's nested in endless layers of curly brackets, they will be running to frameworks like Mojito. Mojito's structure and JSON configuration files unpack much of this complexity and spread it out over a number of directories and files. Some JavaScript programmers may be a bit put off by all of this atomization, but the structure has served the MVC community well over the years.
The flexibility of using pure JavaScript on both the server and client should also be very attractive. Several other projects, including Google Dart and Opa, are trying to create new languages that offer the same code base for client and server, but these approaches require learning yet another language. Mojito runs regular JavaScript, which will be handy when you encounter the weird, edge conditions of the language and need to program around them. There will be differences among browsers for the immediate future, and adding another language doesn't always smooth them over. Despite the improvements offered by the newer languages, most developers will prefer to write native JavaScript.
I think Mojito can have a long and happy life with Web developers who yearn for the structure provided by popular MVC frameworks but are tired of writing different languages. My guess is we'll go through several more rounds of cross-pollination among the various projects fighting for attention. Yahoo did a nice job of extending YUI to handle much of the work on the server. When deeper connections to the various data stores appear, we'll finally have a strong enough structure to build serious applications using only JavaScript.
This article, "Review: Yahoo Mojito gives server-side JavaScript a lift," was originally published at InfoWorld.com. Follow the latest news in software development, JavaScript, and HTML at InfoWorld.com. For the latest business technology news, follow InfoWorld.com on Twitter.
Read more about application development in InfoWorld's Application Development Channel.
This story, "Review: Yahoo Mojito gives server-side JavaScript a lift" was originally published by InfoWorld.
Copyright © 2012 IDG Communications, Inc.