Thursday, November 5, 2009

GWT or Pure JavaScript?

Off late, I have heard of quite a few stories of GWT being "awesome" choice for complicated web applications. "Ideal", "Awesome" are terms subjective to reuqirements but here's my take.

I am apprehensive of the strategy itself. To take advantage of compile time benefits of static languages for behaviors driven by dynamic language targetting already troublesome host environment!! Personally, I favor either a pure JS driven or RIA approach, depending on website needs.

In favor of pure JS driven approach:
- Browser compatibility problems have long been addressed by most modern JS libraries. Build your JavaScript components as extension to JQuery, ExtJS etc.
- For debugging support, you can't really shy away from browser level debugging. Odd that considering JavaScript is in widespread usage for so so long, that IDEs have remained far behind. But with increased stability in browser specifications (sure!) and absence of dog-fights, most browsers provide good support these days. Mozilla, IE, Opera and growing number of additional plugins are getting pretty good at it.
- During development, tools like JSLint can provide you some degree of dev time checks. Tools JSEclipse, Aptana Studio etc also help.
- Testability: Well its far from XUnit level support and integration, but its getting better everyday. It also depends on how you design your UI (pages, elements, scripts), and to an extent to overall web app architecture. Honestly, isn't it the case for any other system?

I recently discovered, js-testdriver. Its awesome, integrates with Eclipse and CI systems. JSUnit is also helpful, but probably you want to consider testability aspects right at the time of designing your Pages and JavaScript components. (Which you should for any system, always)

More dramatically, using Java 6 scripting apis, you can think of mocking DOM, other dependencies. (Now thats adventure :) .. )

- if you design your web layer such that you only work around visual component's behavior rather than rendering itself, you can greatly influence testability as well. for example, an AJAX call returning XHTML(s) that can be used for rendering than JSON and direct DOM manipulation techniques. This way, if you design your server side actions and templates well, you can reuse the views for both page and AJAX requests.

- finally, writing code in JS, is the best way you will write quality code. No code generation tool can help you achieve better understanding/code/design. Don't shy away from it, embrace JS development. Will you adopt a GWT/Script# like approach for CSS too??

Btw, I have used GWT before and liked it very much till I really understood and used JavaScript as an OOPs language, and worked on various Web architecture approaches. Basically really learnt things about WWW.