Thursday, June 9, 2011

The Three Groovy Books I Use Regularly

During the course of my Groovy evangelism, I've often been asked what the best book is for a Java developer to use to learn Groovy. Unfortunately, this is another of those dreaded "it depends" answers. In this post, I summarize why I like and regularly use three Groovy books: Groovy Recipes: Greasing the Wheels of Java, Programming Groovy: Dynamic Productivity for the Java Developer, and Groovy in Action. I hope to be able to provide details as to what distinguishes each book from the other two for those looking for a single book. They each offer distinct advantages in addition to many common advantages and I have found each one to be useful in different situations. The good news is that all three books are excellent in their own right so one really can't go "wrong" with any of them.


Groovy Recipes: Greasing the Wheels of Java

Groovy Recipes was the first Groovy book I purchased because I have found the "Cookbook" approach and "Recipe" approach to be a fairly effective way for me to learn a new language through application of practical examples. As much as I like the common "cookbook"/"recipe" style book anyway, I liked the fact that Groovy Recipes provides it recipes in an order that makes it serve as an adequate introductory book as well. In other words, I did not need another book to give me the basics before diving into the Groovy Recipes book.

Groovy Recipes's Table of Contents demonstrates how the chapters and recipes are structured to almost read like an introductory text. Both the book's subtitle ("Greasing the Wheels of Java") and its introductory chapter titles relay the fact that this book begins coverage of Groovy from a Java perspective. Chapter 2 provides a high-level overview of how Groovy builds upon and improves upon Java concepts and syntax. Chapter 3 covers the many different ways one can run simple Groovy scripts as well as IDEs and other basic tooling support for Groovy. Chapter 4 is a great chapter for a Java developer coming to Groovy as it really emphasizes what Groovy adds to Java.

Not only do the initial chapters provide a solid introduction to Groovy, but even the latter and more advanced chapters continue to show off Groovy features via practical applications while at the same time introducing Groovy concepts and syntax at a level appropriate for those with little experience with the language. I use Groovy largely for my scripting needs. As such, the practical recipes related to Groovy on the command line (Chapter 6) and Groovy's file handling (Chapter 7) are important to me. I also spent a lot of time in Chapters 8 and 9 reading about Groovy's fantastic XML parsing/slurping and writing capabilities. Finally, the latter chapters of this book cover Groovy's metaprogramming capabilities before ending with two chapters focused on Grails.

Groovy Recipes is an excellent book with a recipes-oriented format that is seamlessly woven into introductory-feeling flow. It's a great combination. The only drawback is that Groovy Recipes does not cover as much as Groovy as the other two books I am writing about in this post. For example, I often find myself performing database access from my Groovy scripts and this book has very little to offer in that area.

Groovy Recipes covers a lot and what it covers, it covers well. However, it does not cover some topics and so I found I needed another Groovy book as a supplement. That being said, I liked this book so much, I bought it twice! (I lost the first copy through a not-so-smart move and missed the book enough that I bought it again.) This is the book that "hooked" me on Groovy and got me excited about what I could do with the language as a scripting language. I still use this book, particularly when working with command-line, with files, or with XML in Groovy. This book has the most impressive cover of the three books I review here and, in fact, has one of the most impressive covers I've seen on a programming language book.


Programming Groovy: Dynamic Productivity for the Java Developer

Like, Groovy Recipes, Programming Groovy is brought to us from The Pragmatic Programmers as part of The Pragmatic Bookshelf. In fact, the authors of this book and of Groovy Recipes were originally going to write a single book between them and decided that their respective focuses and intentions warranted two separate books. After reading most of both books, I agree that the different treatment was a good idea as both books provide distinct advantages

Programming Groovy is exactly the type of book one would want if looking for an introductory book that quickly builds on basic concepts. It is well written and follows the "classical" language introduction approach. The Programming Groovy Table of Contents shows that this book starts out with high-level background information on what Groovy addresses as a language and why a developer might want to read more about and learn more about Groovy.

The second chapter of Programming Groovy covers acquiring Groovy and getting a basic Groovy development environment set up. Chapter 3, "Groovy for the Java Eyes," provides a nice introduction to Groovy targeted specifically at Java developers. I found it interesting that this book addresses dynamic typing (Chapter 4) and closures (Chapter 5) before looking at Strings (Chapter 6) and Collections (Chapter 7). The obvious reason for this is that Groovy GDK and other extensions to String and to the Collections are largely based on the dynamic typing and especially the closure features. These first seven chapters are contained in Part I ("Beginning Groovy") and cover the basics of Groovy.

Part II ("Using Groovy") is the more "practical" portion of the book. Chapter 8 of Programming Groovy covers the highly important and highly useful GDK. Chapter 9 covers Groovy's fabulous XML support and Chapter 10 gives me the coverage of "Working with Databases" that I was wanting. Chapter 11 covers writing scripts and classes in Groovy as well as using Groovy and Java together.

Part III ("MOPping Groovy") is the most advanced portion of Programming Groovy. In this part, Groovy's Meta-Object Protocol (MOP) gets extensive coverage in two chapters. Other chapters cover DSL creation, unit testing, and the all-important Groovy builders.


Groovy in Action

Groovy in Action is the largest and most comprehensive of the Groovy books covered in this review. When Groovy Recipes doesn't cover a particular topic and when Programming Groovy doesn't cover it either, I can typically count on it being covered in this book. There is one caveat to that: the topic I'm looking for must have been part of Groovy for a while. Groovy in Action happens to be the oldest of the three books covered here and in some areas it's showing its age. The good news is that the Second Edition of Groovy in Action is anticipated to be delivered in Summer 2012 and is available in in-work form now via the Manning Early Access Program (MEAP). I have high hopes for combining the comprehensive nature of the first edition with newer topics and features also covered. The current cover of the Second Edition shows it being applicable to Groovy 1.7.

The Groovy in Action Table of Contents gives a small test of the thorough coverage of Groovy provided by this book. The fact that the publisher is pursuing a Second Edition is a testament to the selling power of this book. Besides its completeness, another advantage of the book is the high degree of expertise involved. The multiple authors have been key contributors to Groovy's development.


Conclusion

All three books covered in this post are excellent Groovy introductions and references. For pure reference, Groovy in Action may be the strongest due to its comprehensive coverage. For introductory material, Programming Groovy may be the strongest. For seeing how to apply Groovy quickly in daily scripting tasks, Groovy Recipes is probably the best. They are all excellent and I've found all of them to be useful many times over.

3 comments:

bootz15 said...

I haven't read Programming Groovy yet, but I agree with you 100% that the other two books are well worth their weight in GStrings. Waiting for Groovy in Action #2!!

@DustinMarx said...

Sadly, Groovy Recipes appears to be currently out of print. Amazon.com is currently listing it in Amazon Marketplace with prices ranging from $34.49 to $719.26. I'm glad I bought this book (twice because I lost my first copy) while it was still in print.

Dustin

sf_jeff said...

Worth their weight in GStrings?? I thought the main value in GStrings came from them being a light-weight application...

Anyway, if you don't need the intro, then one possible path is:

Groovy in Action
Grails in Action
Groovy for Domain Specific Languages

Grails in Action covers building an interesting website, so it can get a bit of hands-on feedback...