Saturday, July 4, 2009

2009 JavaOne: Groovy/JRuby

The 2009 JavaOne Conference included multiple opportunities to learn about and discuss Groovy. Bill Gloff provides a nice summary of the Groovy-related activities and mentions that Groovy won this year's edition of the Script Bowl. In this blog posting, I will be focusing on two Groovy-related presentations presented at 2009 JavaOne: What's New in Groovy 1.6? (TS-4215) and Comparing Groovy and JRuby (TS-4955).

What's New in Groovy 1.6?

In late 2008, SpringSource acquired G2One, bringing key Groovy developers such as Graeme Rocher and Guillaume Laforge into SpringSource. The latter, Guillaume Laforge, presented Groovy at the aforementioned Script Bowl and was the presenter of "What's New in Groovy 1.6?"

Laforge's presentation was not entirely new to me because I had previously read his article What's New in Groovy 1.6. He mentions in his presentation slides that the examples in the presentation come from the article and suggests reading the article for more detailed coverage of the topics covered in the presentation.

Groovy Overview

In his presentation, Laforge mentions some of the advantages of Groovy that I have significantly appreciated as I have worked with Groovy. I especially like Groovy because it is so easy to apply my years of Java development experience and to mix Java and Groovy; Laforge refers to this benefit as a "flat learning curve" coming from Java. I also like how Laforge refers to Groovy as having a "relaxed grammar derived from the Java 5 grammar."

The "Features at a Glance" slide is a single-slide overview of a subset of nice Groovy features such as Groovy's seamless integration with Java, Groovy's full object-orientation, and Groovy's support of operator overloading.

As part of the introduction to Groovy, the presentation uses the now-common approach of showing a simple Java program that runs as-is in Groovy and then as a much slimmer version that takes advantage of Groovy-specific features. This is the same approach I took in my blog posting Groovy: JVM-based Scripting with Less Ceremony. The ability to write Groovy scripts and applications with anywhere from largely 100% pure traditional Java to almost 100% pure Groovy features is one of the features of Groovy that I find most compelling.

This presentation also introduces the Groovy Web Console. Although I had been aware of this online tool for interactively trying out Groovy, I had never actually used it or even seen it because I had started learning and using Groovy using Groovy from the command line. I tried it out after seeing it in this presentation. Although it is not very difficult to use Groovy from the command line, the web console makes it particularly easy to start using Groovy. For example, I can write a variation of the now-famous one-line Groovy Hello World application and execute it easily within the Groovy Web Console as shown in the next screen snapshot.

As the image above demonstrates, a single line of Groovy can achieve the simple Hello World program that takes several lines in traditional Java.

Performance and Syntactic Improvements

One slide in the presentation focus on performance improvements from Groovy 1.5 to 1.6. According to the presenter, Groovy is now among the fastest of the JVM language implementations. There are a few syntax improvements discussed as well with my favorite being complete support of J2SE 5 features such as enums, annotations, and generics. The presentation points out that Groovy's support for annotations allows it to be used with annotation-driven frameworks and libraries such as Guice.

Groovy Metadata: Abstract Syntax Tree (AST) Transformations

A few slides are devoted to coverage of Groovy 1.6's support for AST Transformations that allow the creation of custom language syntax. Laforge focuses on @Singleton, @Immutable, @Lazy, and @Delegate in this presentation.

Groovy and JSR 223

One of the most exciting features I have enjoyed with Groovy 1.6 is its bundling of a built-in JSR 223-compliant script engine. In fact, I like this so much that I have previously blogged about it. This new feature makes using Groovy within Java code via JSR 223 almost as easy as using the Rhino JavaScript engine that comes with the HotSpot JVM.

Groovy and Java Management Extensions

As proven by the fact that I currently have 43 blog posts tagged as JMX, I really like to read about, write about, and use JMX. It is easy to use any Java APIs and libraries with Groovy, but Groovy 1.6 takes JMX ease of use a step further with the JMX Builder. This presentation devotes a couple of slides to JMX Builder. One slides outlines its main features and the other provides code snippets for each feature. It is a testament to the simplicity of JMX Builder syntax that all of this can be fit onto two slides! I have blogged previously on JMX Builder.

Groovy and OSGi

The last new topic in this presentation is Groovy's "OSGi readiness." OSGi has been a popular topic in recent years and SpringSource has been an early adopter of OSGi, so Groovy's support of it is not surprising.

Summary: What's New in Groovy 1.6?

As stated in his presentation and stated previously in this blog posting, most of the material presented in the presentation is available with different level of detail in the article What's New in Groovy 1.6. If you are interested in Groovy and have not read either, you might want to start with the presentation for a high-level overview and then go to the article for more details.

Comparing Groovy and JRuby

If you are a fan of the original Star Trek series, you will love the slides in this presentation. If you are not a fan of the original Star Trek series but want to learn more about how Groovy compares to JRuby, you will still find most of the slides informative and useful. There are many images from the original Star Trek series interspersed with the technical content of the presentation. I found these images to be not distracting and expect them to generally appeal to the technical crowd without any risk of being offensive as some slides have been recently deemed in at least two recent conferences (Ruby and Flash conferences).

I have been using both Groovy and JRuby in recent months and so was interested to read this presentation and see how Neal Ford's conclusions and observations aligned with mine. In general, he observed many of the similarities and differences I have observed and called out some that I realized were different but had not previously thought about.

I particularly like an early slide in his presentation where he presents an image of a scale with Groovy on the left side and JRuby on the right side and has a single sentence for each. I think these sentences succinctly describe the most important difference (to me) between these dynamic languages: their intent. Ford states that "Groovy dynamicizes the Java platform" while "JRuby brings Ruby to the Java platform." When I have been asked by colleagues about the main difference between the two languages, I have answered this same way, albeit not as elegantly as Ford does.

I have stated that I believe that Groovy appeals most to experienced Java developers who wish to leverage their skills and knowledge in Java and generally are happy with Java, but want to take advantage of some dynamic features, some newer language features (some of which may end up in Java SE 7), and of general script-friendly language attributes. On the other hand, I believe JRuby is more attractive to those developers who either are more comfortable with Ruby or wish to learn Ruby, but need access to the JVM for some reason (such as needing to take advantage of JVM benefits or to use the Java framework or one of its many libraries). Groovy, to me, is really more an extension of Java while JRuby, to me, really is "Ruby on the JVM."

Another interesting chart in this presentation also appears early and shows a horizontal axis representing the spectrum of dynamic to static and a vertical axis representing the spectrum of strongly typed to weakly typed. Although I don't see any notes to conclusively back up my interpretation of this slide, it does seem that the red and blue chips on the chart reflect the fact that both Groovy and (J)Ruby are strongly typed dynamic languages. Graeme Rocher has a similar but rotated slide in his Grails Exchange 2007 presentation Dynamic Groovy - Meta Magic!

This presentation has many slides covering different features that Groovy and JRuby offer as well as the often different approaches each language takes to the same features. Even without notes or the audio of the presentation, these are pretty easy to follow in the slides if you have basic familiarity with some of the key tenets of the dynamic languages.

Some of my favorite slides in this presentation occur in the "Summary" section where Ford outlines "the good" and "the bad" of each of these two languages. I am always suspicious of a presenter's credibility when he or she cannot think of much negative about whatever he or she is talking about. At the very least, nothing is perfect and there always should be situations in which a particular language is not the best fit or has disadvantages compared to another language.

Ford's "good" and "bad" for the two languages include several bullets each, but include the key differentiating characteristics of the languages. Although both will run on the JVM and allow use of Java libraries and JVM features, Groovy is closer to Java (for good or for bad) than is JRuby and JRuby is closer to Ruby. It really comes down to whether one prefers to use a Java-like language or to use Ruby on the JVM.

By the way, I couldn't help but laugh at the slide in this presentation that mentions Perl with an image of a man screaming. That's classic. Although I like both Groovy and JRuby, you won't catch me using Jperl or jPerl or any other form of Perl on the JVM anytime soon.

No comments: