Saturday, June 30, 2007

How I fell in love with GWT

The first Graphical User Interface I ever wrote was in BASIC. I was about 13 when I wrote it, so it was a GUI for a game. You only build important applications when you are young. As you grow older, you compromise on the 'important' part, but that's life I guess.

The GUI didn't do much and it was a very laborious experience by today's standards, but I remember enjoying every bit of it. I am a geek, you know. A few years later I was building a GUI in C. It was more sophisticated, but the effort had gone through the roof. I started using polygons and clipping algorithms and z-buffers and whatnot. I even had a few books to keep me company that still hold a prominent place in my bookshelf.

They got to lie on the floor for this photo, but we've come a long way together and they didn't mind.

Anyway.

Using geometry and trigonometry to create a GUI, made the stuff that I was learning at the time in school actually interesting. Or perhaps it was the other way around. Who knows. It got frustrating after a while though, so when I discovered Windows and the Microsoft Foundation Classes, it felt like a godsend. I even got new books to celebrate the occasion.

But programming for the PC can only get you so far. Now that you can program for your phone, how could you let the opportunity pass? I couldn't. I started reading up everything I could find about Java Midlets and the Symbian OS. No books this time, everything was online. The development experience was great. You could do very little stuff in such a small machine and the process seemed like constantly solving puzzles. The GUI was the easiest part. You got a menu, two soft-buttons and some form fields. That's your interface. You could use any color you wanted, as long as it was black. I had great fun doing it, but my company was making more money in enterprise software, so eventually I found myself working in the Enterprise Java Software world. A place even the brave ones fear to go. Probably because it involves putting an HTML GUI on top of a Java server application, which is as scary as it sounds. If you are not a hopeless geek, that is.

The worst problem with such an arrangement is that you constantly have to context-switch your mind from one language to another: from HTML to Java, then to JavaScript, then back to Java, and so on and so forth. It's the same burden as using straight SQL to access your database (but let's not get into that again). And the tools aren't very helpful, either. The gap between these technologies makes you debug the same use case separately. Nowadays you have to add AJAX capabilities in your web-based apps, which only makes things worse. When I first used AJAX in the development of an HRM system a few years ago, it felt hard. When trying to find out why a certain widget was not getting updated, we had to use a Java debugger to see whether the server was sending anything and then a JavaScript debugger to check whether it was coming to the browser at all. It was madness, I'm telling you.

[By the way, if you have no idea what an HRM is, ask your hiring manager, he uses one. If he doesn't, tell him to give us a call. We can help.]

So when I heard about GWT, I instantly got excited. It promises to free us from the torture of creating the GUI in HTML/JavaScript and the backend in Java and it delivers on its promise. You do everything in Java! You create the interface pretty much the same way you did it with MFC back in the day and it gets transformed into JavaScript code of the highest quality to execute on your browser. All of that in the comfort of your Eclipse IDE. Apparently we have the same taste in IDEs with Google.

I've been reading about it for a year now, but I wanted to get some first-hand experience, before bragging about it. The opportunity came with my new Very Cool Project, which I can't talk about yet, so I'll just call it VCP. It's like VIP, only cooler. The Coolness of the project exists independently from GWT, but this is the icing on the cake. What would have been a technical wonder with a boring GUI, will now become a highly interactive experience that will validate the underlying technology. Just like what happened with GMail. Nobody cared much about Google's low-level technical marvels, until it hit them in the face through the excellent interactivity of the GMail GUI. Hopefully that's what is going to happen with VCP as well, if everything goes as planned. Yeah, I know. Like it ever does.

But with GWT, I feel quite confident. Creating a GUI is so easy that I made the VCP mock-ups in it. We used to do it in plain HTML with web designer tools and when we started developing we would copy the HTML files to JSP ones and change stuff all over the place. It took me only slightly longer to finish the task with GWT, but I already have working code to use. I can use the time I would spend coming up with a first-pass working prototype, to make a trip to Tahiti.

Just kidding. Like they would ever let me do it.

The other thing I like a lot about GWT is that it's open-source. And with the best license, Apache 2.0. This has already been quite handy in VCP, when I stumbled upon a bug during my upgrade from version 1.3 to 1.4RC. A simple request for help in the forum and a bit of source code reading, and I came up with a workaround in no time. And identifying the bug was the easiest part of all. I got a stack trace of my Java code and using Eclipse I could immediately pinpoint the culprit.

There is much more in GWT than that, though. You get easy browser 'back' functionality. No more 'history stack' for us, thank you very much. You can unit test your interface with JUnit. Do that with a HTML/JavaScript GUI if you dare. And perhaps most important of all: cross-browser compatibility. The Googlers have gone into the trouble of coming up with implementations for numerous browser inconsistencies and they have hid them inside the GWT classes. You only program against one GWT API, not against half a dozen JavaScript & DOM implementations.

I still haven't got a proper book about it, though. You know, for company and all. I did however, make the first step: I put it in my wishlist.

Creative Commons License Unless otherwise expressly stated, all original material in this weblog is licensed under a Creative Commons Attribution 3.0 License.