Stu’s series

If you haven’t already seen this, let me totally recommend Stuart Halloway’s series on the languages he call The series look at several different aspects of these languages (Groovy, Scala, Clojure, JRuby), contrast them with each other and Java. Highly recommended if you are in any way interested in the languages that will soon replace Java for much application development.

The three published parts are:

  1. Common Ground
  2. #2: Java Interop
  3. #3: Dispatch

Is Groovy like Java?

I usually don’t mention the G word in my blog – the results have a tendency to be less than palatable. This time I’m going to make an exception though. The reason is that this meme has been floating around as an argument for Groovy, and I really don’t agree with it. In fact, the reason I’m writing about it is because I think the meme in itself generally can be bad for Groovy.

The thing I’m talking about is the saying that Groovy is just like Java. That you can start using Groovy directly without learning anything about Groovy and that basically all Java syntax is valid Groovy.

Now, the last part has never been really true, since there are a few valid Java constructs that are not supported in Groovy (anonymous classes, I’m looking at you). This might be fixed in the 1.5 version. I don’t really know, but that’s not the point. Since Groovy isn’t using the Java parser there will always be a few small corner cases that are not valid in Groovy but Java accepts. This is not a problem, by the way. The only way it can be a problem is when you’re using Groovy the wrong way, or you absolutely need to do something that Groovy doesn’t support. Since one of the Groovy catch calls is that you shouldn’t implement everything in Groovy, this can’t really be a concern either. If you’re using Groovy correctly, you should just drop down to the Java layer for that particular feature.

Now that that part is out of the way, let’s take a look at the other parts of this idea. Namely that you should choose Groovy because it’s just like Java, and you can start writing Java code directly in Java. These statements are definitely true, since you can absolutely pick up a language that way. In my mind, though, this misses the whole point of using another language on top of the JVM. If you’re building an application and chooses to use Groovy for this instead of Java, isn’t the reason that you’re doing that the fact that you expect Groovy to give you something Java does not? And if that’s the case, doesn’t it sound like a disservice to people picking up Groovy to say that they can begin by just programming Java. There is no gain here. Really. In fact, the equivalent program in Groovy and Java will perform much worse on Groovy since there are several layers of dispatching in Groovy that you don’t have in Java. The result? An application with exactly the same source code, but running 10 times slower.

Since this message is mostly used in marketing and introduction facilities, the people it’s geared at are by definition newbies to the Groovy world. Many of them are totally new to dynamic languages. And the first thing they do is write Java in Groovy, find it slow and obviously, from that point don’t understand why you should use Groovy. This is bad for Groovy. Groovy has some extremely powerful features and libraries that can really make your life on the JVM blissful (compared to using Java, for example). Groovy’s integration with Java is top notch, which means that you can always fall back to Java when you need Java specific features. If you’re using Groovy, I think you should use the full power of the language so you can actually get the full benefit of Groovy.

JavaOne: Keynote and Groovy session

I’m sitting in the general session hall, waiting for the first technical general session to begin. Yesterday was CommunityOne, where we had some interesting discussion about dynamic languages within the context of the RedMonk Unconference. Aside from that, the best parts of the day way announcing that Mingle runs on JRuby, and meeting up with all my soon-to-be fellow ThoughtWorkers. They’re a great bunch of people, and we had good fun.

Today was the opening general session, where Rich Green announced some very interesting developments. Among these are the fact that the open sourcing of Java is now complete, that Sun is coopering quite heavily with UN to provide resources for education to areas of the world where this have long been a huge problem. But the most important announcements were about something called JavaFX. I can’t really say I understand it completely yet, but it seems to be an effort to tackle Microsoft Silverlight, and also fix several deficiencies in Swing by providing JavaFX Script (which looks very much like F3. I’m not sure if it actually is F3 or something else.). This obviously begs the question why Sun finds it prudent to invent a new language, instead of using one of the many great efforts existing in the dynamic language communities for this problem. For example, both Groovy, Jython and JRuby have different versions of SwingBuilders, which allow you to rapidly create Swing interfaces with a specialized DSL for this.

Except for that, the general session and keynote was more or less like usual. Very flash, very markety, but still more technical than I imagine other conferences are. And it was fun to see Rich Green being compared to Steve Jobs…

The first technical session I went to was called “Cool Things You Can Do with the Groovy Dynamic Language”, and was presented by Guillaume Laforge and Dierk König. It was a quite good session, but I can’t get away from my general opinions about the Groovy language. So, before I say something about the presentation, I need to describe my feelings for Groovy. Remember, these are my personal opinions, and some are definitely based on feeling without any specific rationalization.

I would really like to like Groovy, but I can’t. I’ve really tried, but I can’t find the Groovy language to my liking. And believe me, for some circumstances, Groovy should be able to fill the gap between Ruby and Java better than JRuby, at least in some cases. The Java integration in JRuby is quite hard, dispatch and overloading makes calling Java code complicated (from an implementation point, not for the user). All of this would be much simpler with the Groovy approach. But no, I still can’t get along with Groovy. The main reason, I believe, is the feeling I get from all code that the language Groovy have grown piecemal, adding stuff that’s neat wherever. I’m not sure this is the actual way Groovy was designed, but it feels like a modern version of Perl. The syntax doesn’t mesh, and there are numerous (small, but nonetheless there) inconsistencies in how things are handled; many of the things that the language provide for you is things that really shouldn’t be part of the language, but part of a library instead.

So, from this point of view, the presentation walked through several new features of Groovy, and lots of things you can do with it. They talked a bit about the new support for annotations and the plans for generics. Some of it was quite cool; I like the builders (but I prefer Markaby to the XMLBuilder), and some of the features are quite handy. But looking back at my earlier feelings I still see a design process more focused on finding problems with Java, and duct taping them with Groovy. (Like this: in Groovy, all exceptions get handled automatically, making it look as if all exceptions are unchecked.) I have no problem with many of these features, but I don’t think it’s a good way to create a general purpose language.

I’ll be back later with more info on the rest of the days sessions.