Tuesday, October 4, 2011

JavaOne 2011: What's New in Groovy 1.8

Groovy in Action co-author Guillaume Laforge (Head of Groovy Development at SpringSource) presented "What's New in Groovy 1.8" (23940) in which he discussed "What's new in Groovy 1.8" and "What's cooking for Groovy 1.9." This presentation was held in Parc 55 Embarcadero. The attendance was surprisingly low (probably between 40 and 50 people) and I believe that Laforge was probably correct when he observed, "I am competing with lunch." I also have to admit that this was one of the sessions I most struggled with deciding to attend because it fits the common situation of a topic I truly love (Groovy), but for which I already have fairly decent level of familiarity with already for that very reason. The advantage of attending these types of sessions is that I know I care about the topic, but the disadvantage is learning less than I might learn in a session on a topic I'm less familiar with. I was glad to see that Laforge's slide welcome slide stated there'd be a look at Groovy 1.9 because I'm less familiar with that version.

The statistics for Groovy 1.7 (Groovy 1.8 statistics not yet available) include 185k downloads of Groovy 1.7 after an initial month of release. He reported 362k downloads that are likely just the "tip of the iceberg" given Maven repositories. He guesses there are one-half million Groovy users. After providing the Groovy 1.7 download statistics, Laforge showed a quick demonstration of Groovy code for the relatively small percentage of attendees who are not familiar with Groovy. Laforge pointed out that most Java developers learn Groovy exactly the way I did; they start by writing mostly Java code and transition to Groovy-isms as they become more comfortable with them and the syntax.

Laforge began his coverage of Groovy 1.8 with "Command chain expressions." This allows the dropping of many decimal points and parentheses in many chained method calls. Laforge indicated that you must provide parentheses when the method does not take any parameters.

Performance improvements are another Groovy 1.8 feature. Laforge stated that there are "significant runtime improvements for primitive int operations" and that the "classical Fibonacci example is 13 times faster." His slide also stated that this has been done since Groovy 1.8's initial release for "all primitive types." Some of the performance gains were acquired by using bytecode opcodes rather than relying on methods on the Integer class with the associated autoboxing/unboxing.

Laforge mentioned the addition of GPars to the standard Groovy distribution. He also highlighted closures improvements such as using closures as parameters to annotations, closure composition, closure trampoline, closure memoization, and currying improvements.

Laforge stated that Groovy is well-known for its XML support, but now supports JSON natively (see my post Groovy 1.8 Introduces Groovy to JSON). He showed examples of using the built-in JSON support and JsonBuilder.

Laforge moved onto covering new AST Transformations in Groovy 1.8. I have blogged on several of these including @Log, @Canonical, @ToString, @EqualsAndHashCode, @TupleConstructor, and @Field. Laforge covered these as well as others such as the execution controller AST transformations @ThreadInterrupt, @TimedInterrupt, and @ConditionalInterrupt. Laforge also provided examples of @InheritConstructors and of @WithReadLock and @WithWriteLock.

Laforge showed examples using Groovy 1.8's compilation customizers and talked about new slashy syntax, new GDK methods, and string to enum coercion.

Groovy 1.9 supports Java 7 Project Coin features and makes use of invokedynamic. There is also effort being placed on making Groovy more modular. They are looking at static type checking and compilation. They are also thinking about using the Eclipse compiler to replace the joint compiler because of some corner cases encountered with the joint compiler.

The features Laforge covered are generally well covered in the Groovy 1.8 Release Notes, which includes some of the examples that Laforge showed. This should not be surprising given that Guillaume Laforge is the one who added that page. I was familiar with many of the features Laforge discussed, but I still learned some new tips and ideas for more productive use of Groovy. It was, as I expected, interesting to see what's coming in Groovy 1.9 as well.