Archive for the 'javapolis' Category

Closures And The Ars Rhetorica

How about those annotations? Haven’t they made the once simple and elegant Java language into a unintelligible mixed-up mess of code and metadata? These are just two outcries of despair about annotations that I found on the Internet, both written by able and experienced Java developers:

“We have been seeing this for awhile via XDoclet, and the .NET community is definitely seeing it. I dunno, maybe it is just me, but it scares me. We need to get out some practices for what should be in annotations, and really hope specs will not do crazy things which have you nesting them 5 times.”“Dion”)

“While the advantages of annotating the code (JSR 175 – Metadata Facility for Java) are somewhat clear to me, I have been wondering what the drawbacks could be. I don’t deny that being able to specify auxiliary information for classes, interfaces, fields and methods is a good thing. What I question is the means we will supposedly use to achieve this, namely, we will be putting the whole stuff directly within the code. If not used with care, annotations could (and most certainly will) massively contribute to code pollution […]”
Val’s Blog

Next, take a look at this code sample and see if you can make sense of it.

@C1(C=2) @C2(C=3) @C3(C=4) @Private(access=PUBLIC) public class c {
    @X1(Y=1) @Y2(Z=2) @Z3(X=3) @Public(access=NONE) private int i;
    @A1(X="A") @A2(X="B") @A3(X="C") @A4(X="D") public void f() {

This is what happens if you unleash a new language feature like annotations into the coding community. All sorts of people start using them to create the worst kind of code you could imagine. Do we really want to enable exoting programming styles like these? Would you want to maintain code like this, with annotations in them?

Of course I’m not serious here. Josh Bloch however, was very serious when he used the exact same arguments against the BGGA closure proposal, in his presentation at JavaPolis the other week. Not that he’s completely against closures, but he did fall back on fallacies like these to scare the audience before coming up with some real arguments against the BGGA proposal. And even those where carefully constructed to discuss only the most complex examples from the BGGA proposal. He “forgot” to show some examples of how closures might actually make life (and coding) a lot easier. Which one do you think is easier to understand and maintain, and is less error-prone?

With closures:

doTransaction(entityManager, {=>
    Person p = new Person("Last name");

Without closures:

EntityTransaction tx = entityManager.getTransaction();
try {
    Person p = new Person("Last name");
finally {
    if (tx.isActive()) {

The one thing I agreed upon with Bloch in his presentation, is that there already is a Java-like language that has closures (among other things) incorporated from the start, and that is completely compatible with Java. That language is Scala. It is tempting to leave Java be and turn our attention to the next step in the evolution. Tempting. However, Java is not dead, not even nearly. The reality is that most of us will be coding in Java for many years to come. Our communal knowledge base and level of understanding of the language will only grow, allowing for more complex features to gradually be built into it–and at the same time, make our code clearer and our lives easier.

Neal Gafter (black hat) watching Josh Bloch’s presentation at JavaPolis 2007
Neal Gafter (black hat) watching Josh Bloch’s presentation at JavaPolis 2007

2007-12-23. 9 responses.

JavaPolis: More About ME

Thursday’s JavaPolis keynote starts with Bruce Eckel doing basically a partner slot — a 45 minute promotion speech for Flex (what else). What’s this doing at a Java conference? How much did Adobe pay for….. — Oh. Okay. I just saw the first demo. I want to use this! Show me more! And it works in everything with a Flash player on it? Where can I sign up?

Stephan Janssen’s keynote on his side project,, (no seriously, there’s some great stuff on there and the new (Flex) version looks very slick), gives me some time to recap the last two sessions I saw yesterday. As planned, I chose the EJB 3.1 session over yet another intro into JRuby on Rails. While EJB 3.1 promises some useful new features (WAR packaging, singleton beans, timer service etc), a whole hour is a lot of time to listen to the ins and outs of features and subfeatures.

Then came the moment we’d all been waiting for: a panel discussion with James Gosling, Joshua Bloch, Neal Gafter and Martin Odersky about the future of computing. Literally the future of computing, where most of us had expected or hoped to see a discussion about the future of Java. So what did I learn from this?

  1. Interviewing is a real profession. A panel like this needs a good host who will ask the right questions, ask follow-through questions that are on everyone’s minds, and most of all, can keep the discussion going. Uncomfortable moments of silence at a table with guests like these, with about 2000 people watching, just shouldn’t happen.
  2. “Closures are sexy.” Guess who said that, completely out of the blue? But more importantly, why didn’t the interviewer touch the subject that everyone expected to guarantee some fierceful debate?
  3. a < b is not the same as a – b < 0. In C. I think that’s even a better t-shirt text than “There’s only 10 kinds of people: those who understand binary arithmatic and those who don’t.”

The Keynote Continues

Sun’s Tim Cramer is next on Thursday’s keynote. “Who’s programming Java ME?” he asks the audience. About five people raise their hands. “Who’s done it with NetBeans?” One hand remains in the air.

This shows my doubts about the ever-recurring Sun demos (usually during keynotes) with SunSpots, robots and phones. Fun stuff, but how many of us are actually using it? Most of us are developing web apps — which is not to say that there shouldn’t be attention for anything beyond that, but this is overdoing it.

One last observation: while I’m in deep concentration for writing this blog post, I suddenly hear Sun’s Java evangelista Angela Caicedo talk about “moving my guys around.” Huh? Oh, she’s talking about sprites.

2007-12-13. No responses.

“Please Neal,” Pleads Gosling

Bob Lee’s session on Guice got mixed reviews. Having already seen his introduction to Guice, I had an pretty good idea of what Guice is, so I enjoyed hearing about his 50 or so best practices and previews of things to come. However, I spoke with another visitor afterwards who was less impressed; he had expected more of an introductory session.
Right now I’m in a GWT session where one of the speakers has been delayed and time is being killed by someone demoing GWT applications somewhere on the Internet, followed by another substitute who starts his presentation with the announcement “Let’s see how fast we can go through this stack of slides.” and welcomes every slide with a half-surprised “Okay…” — has he even seen these slides before?
To start the day off, there was a triple keynote: Stephan Janssen, building up via Bruce Eckel to James Gosling himself. Something that caught my attention on one of his slides: Java would enable you to “Learn Once, Work Anywhere”. Is that really true? Even in the Java EE world I’m in, developers are getting more and more specialized, making a switch non-trivial — let alone the gap that exists between business application and real-time development. Yes, the language may be the same, but different libraries, frameworks, and even the entire context within which you’re working may well require you to virtually start afresh, if you’re thinking about switching.
There was of course some obligatory promoting of NetBeans 6 and Java FX; a short and not very impressive demo with Sunspots and robots (read the book, seen the movie — again!); and a plea to Neal Gafter to get closures into Java 7. Which is kind of weird if you think about it: the “father of Java” asking a Googler to please implement the feature the he himself was unable to include in Java in the first place.

Simon Ritter doing a robot demo

Near the end, I saw a JasperSoft employee losing about 5 litres of sweat: his guest appearance in Gosling’s session went sour when the beamer, switched over to his laptop, remained black for an uncomfortable number of minutes. The gum he was chewing did not help his demo either, by the way.
The GWT session did not end well. Both guest presenters battling for attention, both ignoring any comments one makes about the other’s slides; as well as the text on half of the slides being garbled and unreadable… Fortunately GWT looks slick enough (both code and end result) but definitely needs better promotors.

2007-12-12. 4 responses.

Warming Up For JavaPolis


2007-12-12. No responses.

A Late Arrival

This plan was doomed from the start: leave from work at 4PM and try to reach Antwerp within two hours, so I could collect my badge and goody bag tonight instead of tomorrow morning (together with 2000 fellow JavaPolis visitors). It was worth a try, but I should have known you can’t beat the Dutch rush hour at its peek. Exactly one hour late (an hour spent halfway through in a traffic jam caused by people looking at an accident on the other side of the road) I entered the Metropolis building–only to be disappointed by Stephan himself. So that’s one beer less to drink tonight, in an attempt to go to bed early and be on time tomorrow morning.
Anyway, all will be forgotten when I sit down tomorrow for the first keynote–and after that for all those sessions I’m looking forward to: Gosling, Gafter, Bloch… Sessions about EJB3.1 and Guice and Scala… (Of course, since I didn’t get the goody bag with the program yet, I’m listing all these from memory so I’ve probably forgotten one or two). I’m sorry to say I will probably miss the JRuby session with Ola Bini and Charles Nutter: you can only see so many introductions into Ruby and Rails.
And in the meantime I’ve done a little reconnaissance in Antwerp’s town center after checking into the hotel. As always, the city is great fun to be in Christmas time: nicely decorated and full of life (and beer). I had some Belgian fries at Frituur No 1 and walked around town a little. I nearly bumped into someone looking a lot like James Gosling, taking snapshots of the Antwerp cathedral. Perhaps not the right moment to ask for an autograph…


On the road to Antwerp…

2007-12-11. No responses.

JavaPolis Going Nuclear

Just when I was about to drive off to Antwerp for this year’s JavaPolis, I learned that a fire has started in Antwerp’s nuclear plant ‘Doel’. Apparently the fire is located in a side building and there’s no immediate danger to the public. Which is exactly what I would say to prevent complete chaos from breaking out…

2007-12-11. No responses.

JavaPolis 2006: The Day After

Five days after my nightly arrival in beautiful Antwerpen, I drove back over those same dreary roads to Holland, to my home. Five days that have flown by. I’ve been completely submerged in mixture of Java and a little Ruby. Everything I heard about, everything I spoke about, even dreamt about, was Java. I’ve got so many new ideas, so many things I’m eager to check out or try out:

Many thanks go to Stephan Janssen and the rest of the JavaPolis team for organizing this superb event! I’ll be back next year.

2006-12-16. No responses.

JavaPolis day 4, More on Closures

Late Thursday afternoon, in a packed room 8 of the JavaPolis venue, Neal Gafter presented his plans for adding closures to Java. He had a very well built up argumentation for why we need closures in Java. Not the usual story about the visitor pattern and putting responsibility in the object where it belongs (e.g. iterating should be done by the collection, not by the code that uses the collection). Neal’s argument was all about control abstraction. As it is right now, if you want to enclose some code–for instance, to enclose it with start/end transaction code, or with code to open and close a file that you’re using in the enclosed code–you can do that by creating an anonymous inner class containing the code, and sending that off to the enclosing code. Something like this:

  openFile(file, new Executor() {
    public void run(Object o) throws Exception {
      Reader r = (Reader) o;;

where openFile will look something like this:

  public static void openFile(File f, Executor e) throws Exception {
    Reader r = new FileReader(f);
    try {;
    } finally {

No problem here–until you try to ‘communicate’ with the anonymous inner class. Say you want to set some boolean depending on the contents of the file you’re reading. You can’t–that boolean has to be declared final for it to be visible inside the inner class. And this is just one of the problems you may encounter, like when you want to throw an exception from the inner class. You can work around all of those problems by refactoring the enclosed code. But that’s exactly the point Neal was making: you shouldn’t have to change your code.

In short, the proposal he wrote (together with Gilad Bracha, James Gosling and Peter von der Ahé) would make it possible to write:

  openFile(Reader r: file) {;

This looks nice enough; until you see the code that makes this possible. Unfortunately, in order to optimally fit everything into the existing language structures, a monstrous method declaration involving lots of ugly generics is needed.

Then in the evening, Neal did a small scale BOF session on the same subject, going into more detail. We discussed things like, what arguments exist against adding closures, and also the alternative proposal for which Neal had little praise. If only all JavaPolis sessions could be like this: an audience of 15 instead of 500, a small room, every opportunity to ask questions directly and discuss them in detail.

The proposal can be found at

2006-12-15. One response.

JavaPolis: Closing Already

In the afternoon I attended a session about Phobos. Phobos is a web application framework that uses server-side scripting–JavaScript at first, but they’re already working on support for other languages like JRuby. Phobos’ programming model is less prescriptive than that of Rails, but familiar concepts can be recognized, like a fixed directory structure and a user-friendly url mapping system. There’s tight integration with Dojo and jMaki to generate pretty Ajax-rich scaffolds. Phobos also has an administration console, where you can inspect your deployed application (e.g. mapping rules and deployed scripts)–something that might be useful to Rails as well.

By now I am wondering who has the time to go and use all the stuff that I’ve seen over the last days. What Walhalla-like project will use even three of all those new libraries, frameworks and JSRs that have been presented? For me, after JavaPolis, it’s back to Java 1.4.2, Struts and Maven 1.2. Things like EJB3, JSF, GlassFish, Java 6 or even 5–it’s all purely restricted to hobby projects at home or at best to projects for interns that I’m coaching (they don’t know how lucky they are). Let alone Ruby and Rails. Like walking around in the chocolate factory, knowing you’ll be eating sprouts again tomorrow…

And now I’m off to (hopefully) another JavaPolis highlight: Neal Gafter on closures for Java. For some reason, a more detailed session of his on the subject has been scheduled tonight, at the same time that the JavaPolis movie (Casino Royale) starts. Doesn’t Neal like James? Or is it an intricate test to see who’s fanatic enough about Java to miss the movie? We’ll see…

2006-12-14. No responses.

Revenge of the Groovy Guys

Okay, okay, I’ll humbly admit I was wrong. A little bit. About ehm… that Groovy thing. An inspiring session by … about the Grails framework made me see things from a different perspective. There’s actually some quite nice features in Grails that could well be of use in Rails (or in some cases, Rails on JRuby).

For example, I’ve been looking for some time now for a system that would allow custom html tags in Rails’ rhtml files. The idea is to allow for all sorts of html tags, for example

  <r:for_each list="some_list" var="item">
    <li><%= @item %></li>

This would then trigger a method named for_each (e.g. in a app/helpers/application_tags class) which could process the passed inner html block in any way you want (in this example, probably looping through some_list). Even though Ruby code in rhtml is usually not hard to read, it would still clean things up a bit and get rid of some duplicate code.

In short, it turns out that Grails already has this. Grails also has deployment to war (which is still experimental in JRuby, it’s the first thing I’ll try out once I’m back home from Belgium). And because Grails is built on top of Spring and Hibernate (amongst others), it’s easy to script-prototype your model classes that could be Hibernate-mapped or EJB3s. To be honest, that one isn’t any more difficult in JRuby if you see how easy it is to call any EJB.

Another interesting Groovy/Grails language construct I saw:


The interesting part here is the question mark operator. This will (apparently) check if get() returns null, and if so, prohibit an error being thrown. There was an interesting discussion about this some time ago on (in Dutch; I’ll post the link when I’m home), looking for ways to do this in Ruby.

All in all, I’m still not comfortable with the Groovy syntax (too many curly braces and arrows; and I’m missing semicolons at the end-of-lines–it’s not Ruby after all!) but there’s definitely things to learn and shamelessly steal from those Groovy and Grails guys.

2006-12-14. 6 responses.

Next »