Skip to main content

Why Javascript?

Posted by robc on May 24, 2006 at 5:45 PM PDT

The number one frequently asked question around Project Phobos is: Why JavaScript? Ben Galbraith called the idea of writing your entire application in JavaScript "intriguing", and that's pretty much sums up how we felt when we hit upon it some time ago. Now, with some implementation work under our belt, we've moved it into the "promising" category.

Let's first look at the JavaScript language itself for answers. In the last year and a half, JavaScript has grown in recognition in parallel with AJAX. This has generated demand for good tool support (syntax-aware editors, debuggers, etc.), which is being fulfilled at a rapid pace. Also, some healthy competition among the ever more sophisticated AJAX toolkits has started to fill the most glaring weakness of JavaScript when compared to other scripting languages, i.e. the poverty of its standard library. Finally, the language itself has proven to be usable by mere mortals, at least at a basic level; now the challenge lies with framework implementors (i.e. us) to make sure that as many JavaScript arcana as possible are hidden from a developer's view.

Another set of answers has to do with the JavaScript implementation that we are using, Mozilla Rhino. In our experience, it's a robust, fast, standard-conforming implementation, as testified by the its inclusion in Mustang. Furthermore, a number of Rhino- and Mustang-specific extensions greatly enhance the power of the language, making it possible to implement multiple inheritance, dynamic inheritance, continuations and builder objects a la Groovy. Rhino also supports E4X, further simplifying XML processing. We already use several of these features in Project Phobos and we plan on using them even more extensively as our work progresses.

But I hear you say: isn't the trend in AJAX to completely hide JavaScript from view? After all, that's what RJS and GWT do. Actually, I find it quite remarkable that people would go to such lengths to hide JavaScript, knowing fully well that when the rubber hits the road, in the browser, it's JavaScript that ultimately gets executed. I guess that in the end it'll come down to how good these abstractions are, and whether the illusion that it's really Java or Ruby that you're writing can be mantained to the very end, much like Java tools and debuggers manage to keep the bytecode well out of view. Right now, it seems that the illusion is easily broken when errors (that old scourge of programming) happen, and that the language one gets to use on the server is not quite full Java or full Ruby, since it requires one to follow particular conventions or rules that go beyond the usual ones. By contrast, in the Phobos approach, there is no abstraction, no translation, no hiding anything: it's JavaScript all the way.

Related Topics >>