SpringOne 2GX is in the books

I returned from SpringOne 2GX in DC last week. Lots of good exciting stuff being talked about.

Adrian Colyer, CTO of VMWare, did the intro. There was a great deal of emphasis being placed on the next generation of applications. Mobile applications (big surprise) and the increase of sophistication around clients (impact of tech like HTML5, web sockets (push notification), device agnostic applications, the cloud, high performance infrastructure, big data, and more) where hot topics. Had a couple of speakers get up next and talk about Spring and Groovy/Grails. Interesting to see a little thinly-veiled (but good natured) rivalry between the two camps.

I spent a lot of time talking to people and listening to presentations in the Groovy/Grails space. I admit that over the course of the last few weeks, I’ve gone from a Groovy language semi-skeptic (dynamic typing? Egads!) to a convert. AST transformations are way cool mysterious magic and deliver A LOT of power to POGOs at no or very low cost. Groovy is also great for ad-hoc scripting. Groovy and Java can be intermixed easily. Creation of new DSLs (Domain Specific Languages) is manageable although it seems like there’s a little bit of a learning curve associated with doing it “the right way”. Oh, did I mention closures!?!  And I haven’t even mentioned the syntactic sugar Groovy provides yet.

Some nice things.

  • Native support for lists, maps, regular expression
  • Everything’s an object, primative types and object types in Java are treated differently, in Groovy they’re all the same!
  • GStrings which in spite of their funny name, make working with Strings a bit easier.
  • Lambda-like expressions and Currying. (Oh, did I mention closures!?!)

AST Transformations.

One of the cool features in the Groovy toolbox is that you can add an annotation to your source code and get a lot of built in functionality woven in at compile-time. There are several different types of transformations. A common case is the idea of object immutability. Immutable objects are ones which don’t change after initial creation. The basic properties of such objects are:

  • No methods that modify the internal state of the object.
  • The class should be final.
  • Fields should not be visible.
  • Mutable embedded objects should be guarded (read only versions or defensive copies supplied)

Doing a simple class in Java might look like this…

[ccW_java tab_size=”4″ nowrap=”true” width=”100%”]

final class Person {
final String name;
final Integer age;

private person() { } //disallow private constructor

public Person(String name, Integer age) {
this.name = name;
this.age = age;
}

public getName() {
return name;
}

public getAge() {
return (age!=null ? new Integer(age) : null); //make a defensive copy
}
}

[/ccW_java]

Rather than writing Java code to implement this behavior, you can just use the @Immutable tag in groovy.

[ccW_java tab_size=”4″ nowrap=”true” width=”100%”]

import groovy.transform.Immutable

@Immutable final class Person {
String name
Integer age
}

[/ccW_java]

That’s it! Groovy gives you accessor methods and a contructor for free. Also, changes to Integer will be prevented and any requests for the Integer object will give you a defensive copy. Pretty nice for a single annotation.

[ccW_java tab_size=”4″ nowrap=”true” width=”100%”]

def p = new Person(“Timmy”, 12)
p.age = 12   // results in groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: age for class: Person

[/ccW_java]

[ccW_java tab_size=”4″ nowrap=”true” width=”100%”]

def p = new Person(“Timmy”, 12)

def i = p.age

i = 21  //is fine

[/ccW_java]

Grails.

Grails is a convention based framework that rides on top of common Spring components. It feels like it solves some of the problems also solved by Spring Roo, although they do it considerably differently. The idea of getting a reasonably configured “kick start” on new apps are common to both. Grails is a whole ecosystem and Roo is more of a utility concept. I could be wrong, but I’d bet VMWare will eventually de-emphasize one over the other since they do solve a similar set of problems. Some folks I spoke to who are using Grails seems a little lukewarm about the framework. It’s still new enough that the adoption rate may pick up over time, but in my opinion developing applications with Spring with a good dose of Groovy sprinkled in would give the benefits of Groovy with a proven application framework like Spring.

Leave a Reply

Your email address will not be published. Required fields are marked *