The Source for Java Technology Collaboration
User: Password:



Roberto Chinnici's Blog

May 2006 Archives


Why Javascript?

Posted by robc on May 24, 2006 at 05:45 PM | Permalink | Comments (2)

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.



Introducing Project Phobos

Posted by robc on May 18, 2006 at 05:34 PM | Permalink | Comments (2)

On Tuesday, at the very end of the JavaOne 2006 Technical Keynote, we demonstrated Project Phobos for the first time in front of an external (i.e. non-Sun) audience. The reception was very warm, as confirmed by a number of great conversations we've since had with conference attendees.

Project Phobos is investigating the use of scripting languages in the Java web tier. Currently, we are focused on JavaScript, but we are able to support any number of scripting engines via JSR-223. To prove this point, at our Birds-of-a-Feather session BOF (BOF-9450) we showed JRuby running in the same environment, with JavaScript invoking JRuby and, conversely, JRuby calling into the JavaScript libraries we developed, all courtesy of JSR-223.

The application we demoed is a mashup of two popular sites, reddit and del.icio.us. Since it's hard to describe in writing an AJAX-rich application, I'd like to point interested readers to the video replay of the session (the segment in question is the last one).

We intend to post as soon as possible a Glassfish build which incorporates Phobos support on the project site, including the source code to the demo, so you'll be able to run it on your desktop and see for yourself what the code looks like. (We are currently held up by some minor licensing issues.)

The role of scripting in the demo app is quite large: JavaScript is used not only for all controller code and as the embedded language in JSP-like views, but also to implement the URL dispatching logic underneath and currently even for implementing sessions via cookies. Of course, we are standing on the shoulders of giants, in that JavaScript can take advantage of all the convenient libraries and services that the Java platform provides free of cost. This leaves as our main task to exploit the dynamic nature of scripting languages to deliver a great developer experience for web applications, in particular AJAX-, RSS- and REST-enabled ones.

In subsequent blog entries I'll go over the contents and some of the ideas that are driving Project Phobos.





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds