Creating Domain Specific Languages with Groovy

| by Craig Wickesser Follow 0 Followers on Feb 21, 2008. Estimated reading time: 1 minute |

Today marked the first day of the Groovy/Grails Experience, also known as 2GX, in Reston, Virginia. The conference spans three days and includes forty 90-minute sessions, panel discussions and code workshops. One of the first sessions of the day was Venkat Subramaniam's "DSL In Groovy." Domain specific languages have appeared on InfoQ in the past including an Introduction to Domain Specific Languages by Martin Fowler and Ian Roughley's article on Building Domain-Specific Languages in JRuby.

Venkat's session provided information about what DSLs are, there characteristics, the types of DSLs (internal vs. external), as well as, the Groovy features for creating and using them. Venkat primarily focused on creating internal DSLs using some of Groovy's built-in features:

  • Method Missing - a special method that is called when a method can not be found allowing a developer to intercept the call
  • Categories - allows new methods to be added to any class at runtime
  • ExpandoMetaClass - a dynamically expandable bean

Besides these three features Venkat discussed the lack of constraints that Groovy places on developers and additional features that promote DSLs including:

  • Closures
  • Relaxed rules on the use of parentheses
  • Built-in list and map syntax
  • Property Missing
  • Ability to dynamically add methods to an interface and have concrete classes also have the methods
In deciding which method to use when creating DSLs Venkat did explain the primary differences between using Categories versus the ExpandoMetaClass,
  • Categories allows you to tactically enhance a class
  • ExpandMetaClass is far reaching, global in nature
  • You may not want to affect a class globally
  • Categories provide controlled flexibility

Domain specific languages are continuing to stay in the spotlight and can be created and used with Groovy with its built-in features.

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Video? by Thom Nichols

Was/ are the presentations being recorded? It would be great to see video/ slides/ notes from the presentations.

Re: Video? by craig w

I didn't see any video or audio recording setup. The presentations are available to conference goers and may be available on their website.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

2 Discuss

Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you