Tuesday, November 27, 2007

Javascript

I have recently been spending a little time updating my knowledge of JavaScript. I have not been working on user interfaces in recent years. When I last looked at JavaScript the main advise was "don't". Obviously, that advise no longer pertains. Apart from XMLHttpRequest and AJAX, the two main things that I have found interesting are:
  • there is a much clearer understanding of the nature of the language and design principals and
  • there are now a variety of mature well supported libraries, including Dojo and jQuery. These are not just hokey widget collections, but appear to provide real programming infrastructure.
I am not very interested, at this point, in AJAX. The ability to talk to the server behind the user's back is nice for some discrete, mainly big pipe, applications. It is best where there is more data than you can effectively send at once or where the data is highly changeable. But, AJAX appears to create as many problems as it solves for most applications.

JavaScript turns out to have more in common with Lisp than Java, having closures. Lisp people are prone to making claims about object oriented programming having appeared in Lisp before some other languages, and in a sense they are right. You can implement inheritable, polymorphic, encapsulated things in Lisp using closures, but you need to think about them differently.

A number of writers have been exploring the idea of unobtrusive JavaScript. In this approach, page content is vanilla HTML and behavior is added in an onload script. This is, in a lot of ways, finally applying some ordinary engineering to the problem: separating concerns, regularizing binding, finding techniques to better leverage common logic, and so on. I like these ideas very much and they make JavaScript much more attractive for me. In many ways, it is contrary to a lot of the AJAX trends. Pushed to its logical extreme unobtrusive JavaScript would strip the body of a web page of everything but pure content and that content's natural structure. The AJAX implementations I have seen make the body of the page content free presentation elements.

Finally, when I last looked seriously at JavaScript there were only a few flakey command line EcmaScript interpreters. Now there are some solid looking ones, two from Mozilla! And a number of unit test libraries that I need to look at. It is not clear to what degree the unit test libraries support an emulated DOM. More later.

All of this is probably old hat to people who have been actually paying attention to the JavaScript world, but it comes as news to me. Worth a continuing look.

- J

No comments: