InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Just the Cure, More Groovy

Posted by Craig Wickesser on Mar 01, 2009

Sections
Enterprise Architecture,
Operations & Infrastructure,
Process & Practices,
Architecture & Design,
Development
Topics
Release ,
Groovy ,
Java ,
Version Control ,
JVM Languages ,
Dynamic Languages ,
Languages ,
Source Control ,
Programming ,
Announcements ,
G2One

Actor Christopher Walken once performed a skit on Saturday Night Live in which he proclaimed he needed more cowbell to get rid of his "fever".  In the same light, the Groovy team has certainly heard the calls for more Groovy and have recently released 1.6 of their award winning language.  There are a slew of new features mentioned in the release including,

  • great runtime performance improvements
  • multiple assignments - optional return in if/else and try/catch blocks
  • AST transformations and all the provided transformation annotations like @Singleton, @Lazy, @Immutable, @Delegate and friends
  • the Grape module and dependency system and its @Grab transformation
  • various Swing builder improvements, thanks to the Swing / Griffon (http://griffon.codehaus.org) team
  • as well as several Swing console improvements
  • the integration of JMX builder
  • JSR-223 scripting engine built-in
  • various metaprogramming improvements, like the EMC DSL, per-instance metaclasses even for POJOs, and runtime mixins

One of the primary focuses in this release was on performance and the Groovy team claims to have made significant improvements ranging from 150% to 460%.  Another feature included in this release was the official integration of the JMX builder, which is just another example of community efforts helping to improve Groovy.

Below are some examples of several of the new features including multiple assignments and AST transformations.

// this class' properties are immutable once the object is constructed
@Immutable final class ServerConfig {
  String url
  int port
}

def getServerInfo() {
  ['http://home.net', 8080]
}

// attempts to set a property on an Immutable object
def setUrl(config, newUrl) {
  try {
    config.url = newUrl
  }
  catch (ReadOnlyPropertyException ex) {
    ex
  }
}

// multiple assignment
def (url, port) = getServerInfo()

assert url == 'http://home.net'
assert port == 8080

def config = new ServerConfig(url, port)

assert config.url == url
assert config.port == port

// try to change the property on the Immutable object
def result = setUrl(config, 'www.google.com')

// verify the property change failed
assert result instanceof ReadOnlyPropertyException


The example above shows how the @Immutable AST transformation provides a very simple way of creating a read-only object.  The example also demonstrates using the new "multiple assignments" feature.  For more information about the AST transformations you can visit the Groovy user guide, currently the section only covers the @Immutable transformation.

Now that you've seen a quick overview of what Groovy 1.6 has to offer, check out What's New in Groovy 1.6, an in-depth article about Groovy 1.6 written for InfoQ by the Groovy Project Manager, Guillaume LaForge.  Guillaume covers each of the new features and provides plenty of code examples which help clarify all of the new capabilities.

  • This article is part of a featured topic series on Java
Grape and grab are pretty nice by andrej koelewijn Posted
1.6 is really more effective than 1.5.7 by qiu james Posted
congrats by Roger Pack Posted
JRuby or Groovy? by Joshua Partogi Posted
Re: JRuby or Groovy? by Guillaume Laforge Posted
Re: JRuby or Groovy? by Marcio Garcia Posted
  1. Back to top

    Grape and grab are pretty nice

    by andrej koelewijn

    The build in dependency management makes life a lot easier, especially for scripting. Nice example on my blog with Apache Camel: Groovy and Grape - easiest way to send gtalk message with Apache Camel?.

  2. Back to top

    1.6 is really more effective than 1.5.7

    by qiu james

    But groovy need to improve startup speed.
    gant is too slow so we have to rewrite it in python, or beanshell.

  3. Back to top

    congrats

    by Roger Pack

    congrats to the groovy guys.

  4. Back to top

    JRuby or Groovy?

    by Joshua Partogi

    That is the question now.

  5. Back to top

    Re: JRuby or Groovy?

    by Guillaume Laforge

    That is the question now.


    Groovy, of course ;-)

  6. Back to top

    Re: JRuby or Groovy?

    by Marcio Garcia

    Why not both of them? :)