Groovy Rocked My World!
April 28, 2007
Regardless of the aspect of life, trying to ensure that you take advantage of all the opportunities that knock on your door is next to impossible (especially if you are caught up killing spam all day). I consider myself remarkably diligent at staying on the leading (bleeding?) edge of the technology curve. However, like everyone else, I too have blinders. Today, I learned what my blinders have been hiding from me: Groovy. After sitting through an introduction to Groovy given by Scott Davis at the No Fluff, Just Stuff conference, I am experiencing a paradigm shift. My eyes are revealing to me Wavy Gravy. Where have I been??? During the talk, I had to delete all the gibberish from the screen that my jaw had pounded out when it dropped onto my keyboard. I should have listened to James Strachan back in 2004 when he nonchalantly dropped me the hint, "Groovy is just so...groooovy." Since Groovy only hit 1.0 this past December, I certainly haven't missed the boat, so I'm not going to beat myself over it. But, I do need to jump into now without delay.
If Ruby makes you happy, then Groovy makes you sexy, baby! The Groovy syntax is so concise, readable, and logical that you have to wonder why you would torture yourself with native Java syntax ever again. I like how Scott Davis mediates this debate. "You should use the right tool for the job. When Groovy is appropriate, use Groovy. When Java is appropriate, use Java." Makes sense. You certainly would not want to implement Hibernate in Groovy. You could, however, write application code that uses Hibernate in Groovy. Beautiful. I can already think of a number of other possibilities for using Groovy. Unit tests implemented in Groovy are already a well-paved path, especially given that GroovyTestCase is part of the core language. JSF components written in Groovy are another terrific possibility, and would make component development much easier to stomach. My favorite idea, though, is to use Groovy to create Maven 2 plugins. For that, I can think of a perfectly fitting name: Groovy Mojo!
So what do I think is so sexy about Groovy? From just a very brief exposure, I picked up on...
- transparent generation of getter and setter methods
- named arguments (param:"value") for methods
- groovysh interactive interpreter (similar to Ruby's and Python's interactive shell)
- multi-line, HEREDOC style strings using """
- variable interpolation (EL expressions) in strings
- system commands executed directly from a string
- and the list goes on...
Understand that the breadth of Groovy's strengths is wider than just the syntax. The killer feature is the two-way communication and integration between Groovy and Java. This language isn't a one off like BeanShell, Jython, or Rhino. You can start using this today where ever you use Java. Spring 2.0 even let's you use Groovy script files, read from the classpath, as beans that can be injected into other beans. Groovy can be compiled to Java bytecode and run just like any other compiled Java code (a very grooovy CAFEBABE). I can see myself converting all my little shell scripts into Groovy. I can see myself writing my unit tests in Groovy. I cannot wait to get started. Hold the boat!