Tuesday 13 December 2011

Thoughts on jQuery, DOJO and GWT

Having used both these JavaScript extensively over the past couple of years, I thought I would give some brief notes into my experiences of using them.

jQuery - this library is excellent at marking up a page with some enhancements. Would I write an entire JavaScript based application using jQuery? I would not use pure jQuery on it's own, if I was going to use it for a heavy js application, I would use a framework / set of patterns for ensuring the code does not end up being very difficult to maintain. The main problem with jQuery 'out of the box', is that it encourages developers to manipulate their pages using selectors and performing actions on those selectors. Whilst this is very powerful, it can also lead to very unmaintainable code, because unless you have a good understanding of what is in the HTML DOM, then you don't really understand what these powerful expressions are doing. Some programmers may document what they are doing, but a lot of programmers will not. But, on the whole, if you want some simple enhancements, jQuery is very impressive, a great set of plugins, and we have not had any problems with the library, it seems very stable, which is great.

DOJO - this library differs significantly to jQuery, in that it encourages the developer to create classes and custom components (called Dijit's) from the start. So in terms of the 'programming model', DOJO win's hands down. Where DOJO is not so great (and I was using version 1.5.1 on a legacy browser IE 6), is that some things are hard to do, such as styling a button. Why is styling a button so hard? Well DOJO nests the button in a load of div's or span's (I forget), and each of these layers has a css class associated with it.

See: Style Button for more info about styling buttons (although I do not recommend this method, it does highlight there can be difficulties doing such a simple task).

The other reason I am not so keen on DOJO are a) not many people 'seem' to be using it b) it is slow unless you configure your application to go through their Shrinksafe compiler. But, in general, it is 100% JavaScript application, so unless you have a strong team of developers (and preferably JavaScript ones at that), there is plenty of scope to get yourself into problems.

GWT - It is early days with GWT, but so far I have found the development environment quick to setup. I like the showcase (don't they always look good), and the debugging facilities are great. It is a bit of a weird concept, writing Java Code and spitting out JavaScript code, because we are at the end of the day, still manipulating the HTML DOM. In terms of what you get out of the box with GWT, I am using 2.4 and started using the DataGrid the other day, and found it buggy when adding it to a basic dockable resizeable panel, when taken out of the dockable container, it worked.

The upsides of using the Toolkit are that it is going to work well with Google API's, Map's, Calendar's etc... It still does not seem to have taken off quite yet, a jobserve search will show not it's future is still uncertain:

GWT Trend

Maybe the fact it compiles into JavaScript makes people nervous.

So, what would I use for RIA?

It would depend on how 'rich' it needed to be:
  • If I was trying to write a web based application with some widgets enhanced, I would choose Spring MVC with jQuery.
  • If I was trying to write a really whizzy rich application, I would choose GWT.

The Play Framework looks interesting, but the increase in volume of their forum has not carried on the trend of the previous year:

Play Framework Forum

however, google trends shows there is more interest in it: Play Framework Trends

and just looking at the demo app, it looks like you can just chuck a load of javascript code inline to do stuff, which again, can create a maintenance headache if you have a team of 10 UI dev's going at it.

Of course, if there were graphical elements to the application, then this would bring HTML 5, Adobe Flex and Silverlight into the mix.

The bottom line is that JavaScript is brittle, it always has been, and it always will be. Until the tools for JavaScript improve and developers can get decent refactoring tools / pre-interpreter syntax checking of code, that situation will not change any time soon.

Personally, I think Google needs to try to get rid of HTML / CSS / JavaScript, and create a new type of browser, with a new meta language built from the ground up, where widgets are built into the language, and data is sent in an efficient form (Protocol buffers or Thrift maybe?). Layout and styling should be customizable by the user, just a default hint sent to the browser as a starter for 10.

No comments:

Links