Vita Rara: A Life Uncommon

Gettin' Groovy With It


Categories: | | |

Well, this week after hearing about Groovy and reading a bit about it I decided to take the plunge. I've grown tired of the get's and set's in Java code. It's all boiler plate repetitive, non-expressive junk. I've been listening to the Java Posse for quite some time, and all the talk about language level support of properties got to me. I checked out the Grooy Beans page and was sold.

As a proof of concept I started out writing some integration tests first. I used that as the test bed to get Groovy working with Maven. (I'll write more about that later.) Once I had that done I converted a Struts 2 Action that employed an Action class, a Model and a Query bean (to store the users input) into a single clear concise Groovy class. Three classes became one, rose in readability and it was quick. My Action, Model and Query class had a total of about 40 setters and getters. They're all gone now.

I also started using Groovy for scripting my data imports from client legacy data to our data model for Quadran. Being a Java guy I like it a lot more than working in Perl, which is what I've been using.

I picked up Groovy in Action. I highly recommend it. It's very accessible, has lots and lots of code examples, and is highly readable.

I see myself using Groovy a lot. Closures when combined with multimethods for operating on polymorphic collections looks to be very very powerful. (More later.)

So, if you're using Java, do yourself a favor and check out Groovy. If for no other reason than being able to write scripts in a language that takes advantage of the Java platform, instead of having to keep remembering Perl, sed, awk, Bourne shell, etc.