Groovy is a very nice and effective dynamic language for the JVM. It has lots of Ruby’s features and before JRuby was actually useful was my favorite JVM language. I’ve written lots of Groovy code, from functional testing to scripts that would allow users to write business rules.
Geertjan wrote a post that points to a nice article by Joe Baumann using Groovy as the host language for Internal DSLs. Since Groovy and Ruby shares a lot of characteristics it seems a good candidate to it.
At the other hand, Joe’s example is a bit controversial. Example:
use(DistanceCategory.class) {
def d1 = 1.m
def d2 = 1.yd
def d3 = 1760.yd
def d4 = 100.cm
println d1 + 1.yd
println 1.yd + 1.mi
println 1.m - 1.yd
println d2.m
println d3.mi
println d4.m
println 1000.yd.km
println 1000.yd
The problem, I think, is that he has chosen a very small domain. Joe’s language is about defining distances in different units.
What I’ve learned about Language-Oriented Programming is that it is about creating a language while solving a problem. Groovy is an Object-Oriented language, Object Orientation is about using those things named objects to solve your problems. When one writes 1.km in a Groovy source file is he or she using an specific language or just calling a method?
Although Groovy is a nive host for Internal DSLs I believe that Joe’s example is a form of language adaptation and not a Domain-Specific Language. The 1.km construct is merely a new literal on the Groovy language that he added.

0 Responses to “DSLs in Groovy: Bad Example”