| Please take note: 18/5/2008 Latest news ! gwtClassRun has been released in beta to facilitate GWT application development. Introduction Post Introducing gwtClassRun to aid GWT application development gwtClassRun Site http://geekyware.wordpress.com/gwt-classrun/
|
Introduction
By now, every web developer will have heard of GWT and how fabulous it is in developing web application that works in popular web browser using modern development tools like Intellij, Netbean, Eclipse. GWT utilize a true tried-And-tested component programming and event model using Java which much simplifies the development of interactive GUI web application. This is made possible by dispensing with traditional web development of building web application basically using HTML tags and JavaScript crafted in a web editor, and instead replaced with a productive full-fledged development environment using Java language.
A IDE like Intellij is definitely a must for GWT. Experience the debugging power using breakpoint.
Not only that GWT with its unique Java-to-JavaScript compilation technology, helps the developer to focus solely on develop application rather without browser incompatibilities, it also produces some of the tightest optimised code that rivaled or better the best hardcore JavaScript coder.
Though AJAX technology is the rage nowadays with many libraries and framework that purported to bring the desktop application experience to the mass, it also hamper by the fact that those libraries with their large code size incur a noticeably download and Initialization waiting time that might irk user. It is therefore relieving to find a compelling solution like GWT that helps alleviate the wait.
Having myself programming in both Java and JavaScript for years, I find that compile-time checking of Java definitely ease the development and debugging time especially so in a project that involves many programmers. I lament of many lost hours to find a innocuous ‘bug’ due to inadvertently alteration of a variable’s name in a thousand-lines JavaScript embedded in a webPage by others. Misleading or non-informative error message that popup occasionally because of error doesn’t help. Debugging of JavaScript whether using the venerable FireBug, or Alert window still requires much patience and stamina. At times, in this aspect, JavaScript’s dynamism capability seems more of a hinder than help. It feels like a nightmare trying to debug JavaScript under intense deadline.
So you can see how exhilarating I am to find GWT offers a solution capable of developing a sophisticated application without dabbling a single line of JavaScript (Of course, unless one want to use cool JavaScript library like Yahoo Map, Google Map etc). Needless to say, I feel much at home developing a web application under the sophistication and intelligence of modern IDE environment rather rely entirely on Web Browser or web editor (Isn’t programming suppose to be fun ?)
Coming from Java background that cognizant of writing desktop application, I have to say that developing AJAX-based web application in GWT feel natural and is a breeze to use. A lot of power and flexibility from what seems as a elegant and simplistic framework.
Problem
However, current development with GWT comes with a price. Unlike traditional web development where a developer can easily test individual webpage (Whether design visually or run dynamically) since a page can individually processed by the web server or servlet container, GWT actually makes it tedious, if not impossible, to perform those piecewise operation since everything is ultimately compiled into a single core JavaScript file that is then loaded in browser.
To illustrate the problem, consider the approaches of traditional web development in comparison to GWT’s equivalent.
- Traditional JSP Web Development
To put it simply, a web application is comprises of many pages and the page is mocked up visually using web editor like Dreamweaver, and dynamically-enabled by adding JavaScript and JSP tags and codes. When JSP page is altered, just recompile the page and the web application will be updated.
- GWT Web Development
On the other hand, web application is built entirely using Java class. In GWT, executable class is implemented by EntryPoint interface which consists of a single method
public void onModuleLoad() whose code will be run upon execution. Prior to execution, the GWT project’s respective gwt.xml file will be altered to have its entry-point tag reflection the execution class. Therefore, every class that need to be executed has to implement the interface and gwt.xml change to indicate the relevant entry-point class to run.
So exactly what price to pay for using GWT ? Fortunately, it is not a monetary price since GWT is free and open-source with courtesy of Google
. Still, that price is much subtle and cause much frustration to developer as application size become larger. The price is slow compilation and inefficient testing.
Compilation becomes noticeably and progressively slow as the number and size of Java class file increase. This is due to permutation and computation required to ensure tightest optimised code possible. Despite measurement such as setting it to generate only for specific browser to reduce compilation time, it could not resolve the fact that application size does increase and compilation time will increase accordingly, often exponentially, not linearly (Remember it is permutation). This is exacerbated when third party GWT libraries will eventually use Java rather than JavaScript to take advantage GWT’s code optimizations. Even running in modern hardware such core2Duo notebook equipped with 2Gb ram, I couldn’t help but balk at waiting time of no less than 10secs to test a still-developed application.
Notwithstanding, the worse thing is that most time is wasted to compile irrelevant classes into JavaScript that will not be tested because of the hassle as highlighted previously require to test specific class.
Still, other will like to say unit test is supported by GWT but this is not without creating helper class again.
Before recommending the solution, I will first like to describe the enjoyable experience of developing a desktop application using Java in a IDE because this experience is what propelled me to improve on web development using GWT.
One wonderful thing about Java is that each class is self-testable and runnable as long as there is a main method exists in the class with the signature:
public static void main(String[] args)
So a GUI application is build incrementally, with each class construct and test easily through its main method. In Java, everything is class, and Dialog, Windows, Application are all represented by class and testable in its own right.
So a IDE augment the productivity by giving the developer a convenience option to run or debug a class as long as a acceptable main method is available (Generally as a menu choice), with no question ask. At the same time, developer can also create a definable configuration with its own setting and specific class to run when invoked. In most time, developer will likely be interested in testing the class under development not the application as a whole (eg One run the method directly without having to click a button to invoke a class method)
And this way of development is very productive, to say the least, and efficient because IDE only intelligently compile the Java class and its related modified class that change and run it and need not wrap it into JAR file until deployment. You can just as easily test a class not the whole application.
So in thinking out solution for GWT’s noticeably slow compilation, I curiously and playfully think along the same line of
What can’t the same Desktop Application Development paradigm be applied to GWT since GWT is attuned in developing application not web page ?
Proposal
A mindset change required that the developer run and test class (Whose size can be compiled and run faster) more often than whole application (The increasing size means long waiting time).
Taking the clue from the Java development, the following solution is proposed. The feasibility of such solution depends not only from GWT but also explicit support from the IDE.
Designate a special optional executable main method in GWT’s Java class that will be executed upon invoke manually by developer.
public void main()
A class that implements EntryPoint interface indicates that this class will be executed upon running the GWT’s project. However, by putting a main method, any class will be executed upon manual invocation by the developer only. For example, one can access class function by context menu as shown in IDE.

Using GWT’s excellent dead-code removal capability and other sophistication, only the relevant class and its related classes are then compiled into JavaScript, and then run in browser. In this way, unit class is executed and tested rather than only those from EntryPoint class. A default configuration is also assumed by IDE for those class that invoke through main method.
GWT may also like to include helper class that facilitate testing of class eg TestRoot.
Main method is generally used for testing by IDE and not access as a normal usable method. Sometimes, this method could have a lot of heavy lifting, therefore GWT by default will automatically remove this irrelevant method during compilation. Still if the developer want to include this in resultant file then a annotation can be used to mark it as special.
@IncludeMain
Example of GWT Java class using main and annotation

Note that this method doesn’t replace the quest of improving the compilation time (After all, the whole web application needs to be tested and deployed ultimately), but rather serve as complementary way to use GWT effectively and efficiently as possible.
Conclusion
With this in mind, I will like the GWT team to seriously consider this useful enhancement in the forthcoming release of GWT because this really help to improve the productivity of developer through testing only pertinent class without incurring the consuming time require to compile superfluous code or altering configuration file (eg gwt.xml) using the sole EntryPoint approach. This also be plausible solution in long term for large enterprise application development.
.


[...] in beta. The work begin on 24 April 2008 after around the week I suggest a proposal entitled Improving the development experience of Google Web Toolkit to propose a better way of building GWT application by making it easy to run a EntryPoint class so [...]