The guys over at Packt Press sent us a free copy of Groovy for Domain Specific Languages to review for the Grails Podcast. We’ll talk about it in an upcoming show, but I promised the publisher I’d post some thoughts on my blog, so here we are.

First, I’m super excited that there is now a title dedicated purely to Groovy DSLs. Every time I hear Guillaume or Paul talk about DSLs I get swamped with great ideas that I’ve never really had time to explore. This book gave me a reason.

First up, this book is intentionally targeted to straight Java devs, so you get a lot of space devoted to things that even casual Groovy guys will already know. There’s the inevitable chapters on Groovy essentials, using the standard builders, Java integration, and even a chapter devoted to teaching you Grails! (Some people spend entire books on just that.. but I digress. :-) To be honest, this would not serve you well as your first book on Groovy, so I’m not sure some of that content was well served, but I can appreciate the publishing pressure of reaching the widest possible market, and the background material is well done.

What I was really hoping for was some coverage of DSLs from the ground up, and I was really happy. The author spends the whole of Chapter 3 just on closures. This is well worth it. There are tons of edge cases here that I wasn’t across and I really appreciated the dedicated coverage. Straight after you do the closure deepdive, you spend chapter 4 retrofitting Twitter4j with your own basic DSL. The examples were exactly at the right level here, and I was loving the gentle pace.

Groovy Book Review logo

Chapter 5 moves on the standard Groovy builders to give you a feel for some of the standard DSL strategies, but this is space better covered in the Groovy in Action though usefully introduced here. Seasoned groovy programmers will find this fairly skippable, but Java guys will be served with a good grab-bag of examples to clarify their thinking.

Chapter 6 is another “examples” chapter, this time with Grails, Gant and a range of BDD tools (including Spock). Given the spread, the chapter is long but terse and I would liked to have seen chapters 5 and 6 collapsed into a tighter chapters of “DSLs to shape your thinking”.

Chapters 7 and 8 deep dive on Builders and writing your own DSLs - and these represent the heart of the book. Tons of good information in here that you’ll only find scattered across tons of Wiki pages. The book is worth it for just these chapters. You’ll get a feel for builder strategies, along with a “from scratch” DSL creation. Great info in here. I’ll reference these chapters a lot when I work up the keen-ness to tackle my own DSL.

Chapter 9 rounds out the book with a Java/Groovy integration chapter. Didn’t quite follow how this linked to the DSL concept, but if Packt were only going to release one Groovy book, I can see why this material would be good background.

Overall? I’m really glad there is now a dedicate DSL book! This a really solid book on Groovy DSLs that doesn’t shy away from the hardcore material, but still gives you the stepping stones to get there. To be honest, this book could be a lot better if the editing team took a knife to a lot of the non-DSL stuff and sharpened up the book’s vision. The material is well-written though, and I’m sure I’m going to be referencing this material.

While the next version of Groovy in Action promises a dedicated chapter on DSLs, this Packt title gives you a good fill of DSL-centric material to implement today. A solid book that’s definitely worth a look if you want to explore DSL creation more seriously.

Happy DSLing!