Archive for the 'Programming' Category

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;
      r.read(...);
    }
  });

where openFile will look something like this:

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

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) {
    r.read(...);
  }

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 http://javac.info.

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>
  </r:for_each>

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:

Book.get(params.id)?.true

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 rubyenrails.nl (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.

JavaPolis day 4, The Monkey in the Details

On Thursday, Marc Fleury finally delivers his keynote on the open source business. I get distracted by circumstantial details like Fleury’s ridiculous “Public Enemy #1” costume (reminds me of Steve Ballmer’s stupid monkey dance) and An running around him with her camera like a groupie, trying to catch Marc’s best angle (what lens is she using? why does she never use a flash?). Oh man, Marc is actually dancing now. See you soon on Youtube…

(I can imagine you’re getting tired of my supposedly witty blog post titles. Don’t hold back, let me know, leave a comment!)

UPDATE


Marc Fleury at the mike for his JavaPolis keynote

2006-12-14. No responses.

« Prev - Next »