Thursday, August 31, 2006

Walking the Java Road

I am walking the Java road. This week I told a junior programmer that learning Java is not something you start and then complete. Its a road; you learn as long as you are doing it. I am on the Java Road for 5 years now and I am still learning every week, almost every day even.

So what about this Ruby Road over there? It is a lot smaller road, but it appears that only fast vehicles are allowed. You really need to steer well, no mediocre developers here, they've crashed way behind you. And when you finally get it, boy, you get to go fast.

The major problem with walking on 2 roads is that you only have so much time in your life. I need time for the ones I love and then I need some sleep now and then. I would not mind switching, but then there should be enough work. Unfortunately, all the interesting stuff is still in Java. So for now its Java for me. But I'll keep looking...

Thursday, August 24, 2006

Profict Java Summer Camp - AJAX

I am just back from Profict's AJAX day, a very nice way of promoting one's company among developers. There were 2 speakers: Greg Murray, the AJAX architect from Sun and Bram Smeets, the DWR expert from Interface 21. In between there was a small product presentation from BackBase.

4 hours for Greg Murray
Four hours were filled by a jetlaged Greg. It seems that because he got so much time he could not chose what to tell from the many presentations he brought with him. It was a shame everything was so jumbled up because there were some really nice things in there. Without going into too much detail, here are some of the things he presented.

jMaki
Greg is the main author for jMaki. jMaki is a small toolkit that allows you to wrap other Javascript toolkits (among others Dojo and Zimbra). jMaki comes standard with some nice widgets. Besides the usual datepickers and autocomplete stuff, there were some very nifty widgets that allow you write Mashups with Flickr, Yahoo Geocoder and Google Maps. A Mashup is a mashed combination of several web applications. One of his examples was a reworked Petstore where each pet was indicated on a map. jMaki is available for JSP and JSF environments. But given the raw components (simply a html, css and js file) you can probably include this stuff in any other framework easily.

jMaki also has some other basic stuff. For example an eventing mechanism (modeled after Dojo) and XmlHttpProxy. XmlHttpProxy is an XmlHttpRequest like feature that will allow you to call services in any domain by proxying the call on a server. This circumvents the security mechanism of Javascript in which you can only do HTTP requests to the domain from which the page was served.

AJAX, Back button and Anchor links
The trick of the day was the use of anchor links (the part after the #). When the user triggers an AJAX action (for example loading a different product), the URL of the currently loaded document is changed, but only in the anchor part. Since only the anchor changes, the browser will not reload the current page, but will add an entry to the page history. This means that suddenly the AJAX enabled page has a bookmarkable URL. In addition, much better back button support becomes possible.

Bram Smeets on DWR
The 1 and half hour presentation from Bram was a very nicely done introduction to DWR. In contrast to many other Javascript toolkits, DWR only provides communication between JavaScript and Java. However, as this presentation showed, DWR does so very well. In short, the idea behind DWR is that you can call a Java method directly from Javascript, and then can use the returned objects as if they are plain Javascript objects. If so desired, some utility Javascript functions can easily convert these objects to HTML and put them into the current page.

First an example was presented for DWR with plain Java and XML configuration. The few lines of Java and Javascript code on the slides showed that DWR is really a convenient thing to use. One of the killer features is a debug view of all exposed classes and methods. After a pitch style introduction of Spring, Bram then showed how to configure DWR from Spring. Though the integration is indeed nice, it gives you no advantages when you are not using the Spring bean container for some other reason (which of course there are plenty).

Reverse AJAX
The audience really heated up with the topic of Reverse AJAX (a.k.a. Comet, Long poll and for some even as Pushlets). This experimental DWR feature allows you to execute Javascript from Java. A very very neat example showed a method call on a Java-Scriptaculous 'impersonator' on the server side, with as result that the Scriptaculous effect is applied in the browser. Unfortunately Reverse AJAX is still at an experimental stage. As Bram told me later, this is mainly because it has not been tested properly in many circumstances. In addition, you must be very aware of the load this brings to your server.

Barbecue
The day ended with a nice barbecue in the beautiful garden of Profict's castle.

Monday, August 7, 2006

Swing Date Pickers

Back in April I looked around for a good open source Swing date picker for a big Swing project. I found 6 and I actually tried them all. But in the end we simply stayed with JSpinner components.

These were the must-have requirements:
1. support for typing dates directly (this is, without opening a pop-up)
2. ability to limit the selectable dates with a lower and/or upper boundary
3. good event mechanism

And some nice-to have requirements:
4. visual mouse selection
5. support for multiple date formats
6. look good
7. further limitation of selectable days, for example no weekend days

These were the date pickers I tried:
- JCommon
- MDateSelector
- SwingX's date picker
- UICollection's date picker
- JCalendar
- And there was a sixth, but I can not find it back anymore.

None of these met the must-haves. In particular requirement #1, keyboard support, is only present in the the SwingX component. In contrast good old JSpinner supports #1-#3 splendidly, but fails miserably on #4-#7.

However, my search did seem to have some result.

It started with comment on an introduction on the SwingX JXDatePicker by R.J. Lorimer on JavaLobby. This guy writes good stuff. Then I thought, why not ask on the SwingX forum directly. So I wrote this message in search of more features. The message was followed by a lively discussion in search of requirements.

It seems that the SwingX guys picked it up and are now working on the final killer Swing date picker component!

Sunday, August 6, 2006

The Pragmatic Programmer - Book review

A colleague from the company that currently hires me, proudly told that they have a copy of the The Pragmatic Programmer for every 3 employees. Having just finished the Spring MVC book, I thought lets see what this is about. So I read the book and here I will convince you to read it as well.

After only a few chapters 2 strong thoughts came up and remained there for most of the rest:
1. What a dull book, I am already doing this stuff. But more importantly:
2. This is Good Stuff, I wish more people would read this book.

Though the book is old (2000) it is still very relevant. It contains a large set of well described programming practices and attitudes. You can read the entire book in any order. From experience I can say that what this book says, will really help you build better code more quickly.

One point I loved, is when the authors write off the construction metaphor (which is so previous century) in favor of the gardening metaphor. 'Gardening' is much better for explaining to business people why you sometimes need to spend time with no visible improvements.

I wondered why I had never seen iContract before, which is I think a hidden gem of the book. Apparently it is only recently resurrected.

As a totally unrelated bonus, I finally understand the use of Linda like technologies (Rinda/JavaSpaces).

Some minor points:
- I only noticed one trend away from this book: things like Active Record makes the section "Code generators" a bit redundant. Of course it can still be useful. Just watch out for software in which you don't need it.
- Exercise 23 states that it is a good idea to set java references to null after you are finished with the object. I disagree. You can consider doing this when you are writing code for a particular (old) JVM version that you happen to know intimately. And even then I would say that your methods are too long.

Anyways, the book does justice to its title; all tips are practical and executable. The more people will use ideas from this book, the less bad software I will have to work with. So here is my request to all colleague programmers: please go and read this book!

Author blogs: Andrew Hunt and David Thomas