Mykel has posted 1 posts at DZone. You can read more from them at their website. View Full User Profile

Review of Groovy for Domain-Specific Languages

10.12.2010
| 4482 views |
  • submit to reddit
Published by: Packt Publishing
ISBN: 184719690X

Reviewer Ratings

Relevance:
5

Readability:
5

Overall:
4

Buy it now

One Minute Bottom Line

Groovy for Domain-Specific Languages is an excellent introduction to the fairly difficult subject of creating DSLs.  The book is short enough to make it a weekend or 3-day project and the knowledge gained will be useful. 

Review

One of the more widely held beliefs among software developers is that if we can just make the software simple enough to use, we won't have to do quite so much technical support and documentation.  Another, and probably more valid, belief is that by writing more flexible applications and frameworks, we can get more bang for the buck for our time.  Unfortunately, someone still has to configure, specify or otherwise control our applications and frameworks.  To this end has arisen the Domain Specific Language, or DSL.  DSLs come in a variety of types, but one such is the "executable language", where an application or framework makes an execution environment for the DSL.  This is to distinguish it from a generated parser type of DSL .  Groovy, being a scripted language with strong metaobject protocol support built in, lends itself well to writing executable DSLs.  But how does one learn to write DSLs in Groovy?  There are resources on the groovy website, but they lack extensive examples.  A book dedicated to the subject like this one can help expand your knowledge of this frequently difficult subject.

Like many technical books, the first chapter was an introduction to the concepts of DSLs and the next couple are absorbed with general Groovy information best learned elsewhere.  Despite the protestations of the author, it's highly unlikely that someone completely unfamiliar with Groovy would dive right into writing a Groovy-based DSL.  For general Groovy information, get Groovy in Action from Manning.

Once past the intro to Groovy, however, the subject matter starts to take on serious weight.  Starting with details on the implementation of a fairly simple DSL, the reader is taken along a path of increasingly more complex and more "DSL-like" implementations of the examples.  Solid explanations of  DSL-specific subjects surrounding the the meta-object protocol for Groovy was  followed by excellent descriptions of several existing Groovy-based DSLs, like GAnt and GSpec.  A substational number of pages were dedicated to GORM, the Grails glue to hibernate, but didn't really provide a lot of value beyond the existing GORM documentation.  The sections with the greatest value, past the elements of metaprogramming,  involved implementation of a rules DSL that would be very easy to re-purpose for your own needs.  The work closed with a chapter on integration.  This section was brief but seemed like an afterthought.  However, given the solidity of the interior of this relatively short book, that wasn't really a detraction.

As is common with Packt publications, when reading this book it seems best to do so from front to back as a series of lessons rather than trying to use it as a reference manual or skipping around.  The knowledge builds across the flow of the book, so starting in the middle can leave the reader feeling somewhat lost.

PROS:
As previously stated, this is very solid instruction in the basics of generating a DSL in Groovy.  The style tends to be generally succinct without a lot of fluff.  The author seemed occupied with providing real working knowledge to solve real problems.  The examples (nearly always) worked and were usually very clear.

CONS:

With only 9 chapters, dedicating 3 of them to relatively tertiary subjects made the book seem even shorter.  Also, a few of the examples in the downloadable source code were clearly not meant to be run from the command line, as they failed when tried but passed in the Groovy console.

Overall, I would strongly recommend this book for anyone trying to implement any sort of DSL in a JVM-based environment.  Groovy's seamless integration into running Java code makes it a clear choice, and this book's excellent presentation and solid examples provide a good foundation to build upon.

Published at DZone with permission of its author, Mykel Alvis.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Dave Newton replied on Sat, 2010/10/16 - 9:19am

As long as you ignore a lot of the code as printed (and much of it as downloaded), some of the book is okay. But syntactical errors like "[1..9]* each" is *bad*, both because if you're new to Groovy, you won't know why what you typed in doesn't work, and because [1..9]*.each doesn't make any sense--it should be (1..9).each.

The example DSL from Chapter 4, GeeTwitter, no longer works at *all* and as of a week or two ago hadn't yet been corrected to allow for Twitter's OAuth change, and there are *several* serious code issues until the final version of the code is printed, and even then, it's incorrect until it's turned into a script subclass.

As with most other Packt books, it uses code examples as fillers, using complete, redundant examples when a snippet and minor expository text would do. The editing process takes a back seat for both the code and prose. While much of the information in the book *is* good, what could have been a great book is reduced to a passable one, with the caveat that you'll need to just write a bunch of code you should have been able to download, and debug it yourself.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.