Skip to content

Back to Groovy

February 26, 2008

After being initially interested in Groovy I cooled on it as a language and haven’t touched it in some time. Recently I had need to create a little throwaway program and gave Groovy another go.

Groovy is now up to version 1.5 and Grails which is heavily inspired by Ruby on Rails has recently release their 1.0 version. As a programming platform it’s matured a fair amount since I first looked at it. One of the reasons I chose to give it a go it that it has good support in my IDE of choice – IntelliJ Idea. The Groovy/Grails plugin while still a little rough around the edges does a good job of getting you going with Groovy quickly. So far I haven’t had the chance to play with Grails yet so I can’t comment on how well that works.

One of the things you notice straight away when working with Groovy is how easy it is for a Java programmer to get into the language. Groovy syntax looks very similar to Java and in many cases you can paste Java code in and it will work. Obviously though if you’re pasting Java code into a Groovy file you’re not really utilising the full potential of the language. The main point of Groovy as far as I can tell is to address some of the pain points in Java.

Groovy like the upcoming ECMAScript 4 lets you optionally type variables. I like this trend in language design. It lets me decide when typing is important to me and to let me ignore it when it’s not.

The project I was writing involved scraping some info from a web page and doing some manipulation of the data. One of the big noticeable improvements I noticed very quickly was the ease at which collections are managed. Collection manipulation in Java is positively frustrating in comparison. Ranges/closures/high order functions/collection literals all help immensely here.

Another big help was the oddly named XMLSlurper. This lets you navigate DOM structures very simply. Just take a look at XMLSlurper documentation page for a good feel for how easy DOM manipulation can become.

Of course to work with XMLSlurper I had to convert the HTML into XML and for this I used a Java library called tagsoup. This is where the integration between Java and Groovy shines through as there is very little impedance mismatch between the two languages since they both ultimately inherit from java.lang.Object.

Overall it was a pleasant experience using Groovy and I’d love to do a larger project with it in the future.

From → Groovy

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: