Groovy Recipes Greasing the Wheels of Java
Buy it now
One Minute Bottom Line
If you've heard the hype about Groovy but haven't jumped in to see what all the buzz is about, this is a good place to start. This books serves as both a reference and a guide to learning the language.
Groovy is a dynamic language that compiles to bytecode and runs on the JVM, just like Java. Its goals are to remove much of the overhead that Java programmers put up with in their daily coding. Also to provide features common in other languages, but are missing in Java, for example closures. If you are a Java programmer and looking for another language to learn, Groovy is a great place to start.
I was excited when I received Groovy Recipes by Scott Davis. If you have ever heard Scott talk at a No Fluff Just Stuff symposium, you know that his enthusiasm can be infectious and I wanted to see if that translated in his book. I was not let down. His writing style is straight forward, with just enough humor to be good, but not so much that you get side tracked. Groovy Recipes covers a wide range of topics in Groovy. Starting with where to go to get the latest version and setting it up to using the Grails web framework. As with any book that covers a wide range though, there were some things I wish had been left out and other things I with had been put in.The things I liked:
1. Being steeped in Java programming for many years, I found the book covered the differences between Java and Groovy very well. Chapter 3, New to Groovy went over several pieces of the language and it felt that it had Java programmers in mind. Optional semicolons and parentheses, duck typing, safe dereferencing and GStrings (not a typo!) are well covered.
2. XML Parser and XML Slurper. Any Java programmer knows how to parse XML into an XML document and get information out. Groovys XML Slurper offers another way to do this without all the null checking involved in Java. The concepts between these two parsers is covered in detail and the examples cover ways to decide when to use the appropriate one.
3. Good coverage of Metaprogramming. This is one of Groovys strengths, but can be challenging if coming from a statically typed language (C or Java). Ruby, Smalltalk and other dynamic languages have these features. Groovy's online documentation is better than some languages, but the detailed examples in this book go into more detail.
The things I didn't like:
1. XML Builder is explained in detail and Ant builder is mentioned throughout the book. I would have liked to seen some examples of the SWTBuilder. The book seems geared towards work done with hmtl/xml and the web, but this was one item that it missed.
2. Grails and using Grails for webservices is covered. The webservices chapter seemed a little off the mark. I don't know how many developers are going to write an rss feed for an podcasts. I understand that this was done for example and to show the several types of output available in Grails. But if you are going to use Grails, you will need to write a GSP at some point. While this is briefly covered, I think more examples about the presentation of html could have been covered. Also, an AJAX/Grails section would have been great.
Overall, I think this book does a good job of concise examples of common usage of Groovy. The book is laid out well and builds on itself. I think that coupled with the fair amount of documentation available at codehaus, this is an excellent reference.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)