The Art of Groovy Command Expressions in DSLs

NFJS, the Magazine - September 2011

Domain Specific Languages (DSLs) are often littered with the accidental complexity of the host language. Have you ever seen a supposedly "friendly" language expression like "ride(minutes(10)).on(bus).towards(Basel)"? The newest version of Groovy contains a language feature that aims to eliminate the noise of all those extra periods and parenthesis so that your DSL looks more like "ride 10.minutes on bus towards Basel". This article shows you, step-by-step, how to use Groovy Command Expressions and plain old metaprogramming to write just this DSL, and also offers advice on when, and when not, to use this new language feature.

An online version of this article is not available. This article is available in PDF, MOBI, and EPUB to those who have subscribed.

About Hamlet D`Arcy

Hamlet D`Arcy

Sr. Java/Groovy Developer, Groovy Committer

Hamlet D'Arcy has been writing software for over a decade, and has spent considerable time coding in C++, Java, and Groovy. He's passionate about learning new languages and different ways to think about problems. Hamlet is the founder of the Basel-based Hackergarten open source coding group, and regularly participates and speaks at local and international user groups and conferences. Hamlet is a committer on the Groovy and CodeNarc projects, and is a contributor on a few other open source projects (including JConch and the IDEA Groovy Plugin). He blogs regularly at http://hamletdarcy.blogspot.com and can be found on Twitter as HamletDRC (http://twitter.com/hamletdrc).

NFJS, the Magazine - September 2011

NFJS the Magazine - September 2011

In this Issue: