InfoQ

News

Creating Domain Specific Languages with Groovy

Posted by Craig Wickesser on Feb 21, 2008 10:47 PM

Community
Java
Topics
Domain Specific Languages
Tags
Grails,
Groovy

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.

2 comments

Reply

Video? by Tom Nichols Posted Feb 22, 2008 7:26 AM
Re: Video? by craig w Posted Feb 22, 2008 1:04 PM
  1. Back to top

    Video?

    Feb 22, 2008 7:26 AM by Tom Nichols

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

  2. Back to top

    Re: Video?

    Feb 22, 2008 1:04 PM 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.

Exclusive Content

VMware Infrastructure 3 Book Excerpt and Author Interview

VMware Infrastructure 3: Advanced Technical Design Guide and Advanced Operations Guide provides a wealth of practical insights into setting up virtualization in todays corporate environments.

Using Ruby Fibers for Async I/O: NeverBlock and Revactor

Ruby 1.9's Fibers and non-blocking I/O are getting more attention - we talked to Mohammad A. Ali of the NeverBlock project and Tony Arcieri of the Revactor project.

Agile and Beyond - The Power of Aspirational Teams

Tim Mackinnon talks about the aspirations behind the Agile principles and practices, the desire to become efficient, to write quality code which does not end up being thrown away.

Concurrency: Past and Present

Brian Goetz discusses the difficulties of creating multithreaded programs correctly, incorrect synchronization, race conditions, deadlock, STM, concurrency, alternatives to threads, Erlang, Scala.

ActionScript 3 for Java Programmers

Often the hardest part of changing technologies is language syntax differences. This new article provides Java developers with a transition guide to Actionscript which forms the foundation of Flex.

Neal Ford On Programming Languages and Platforms

Neal Ford talks about having multiple languages running on one of the two major platforms: Java and .NET. He also presents the advantages offered by Ruby compared to static languages like Java or C#.

Future Directions for Agile

David Anderson talks about the history of Agile, the current status of it and his vision for the future. The role of Agile consists in finding ways to implement its principles.

Nick Sieger on JRuby

Nick Sieger talks about the future of JRuby, Java Integration, and his work on JEE deployment tools for Ruby on Rails like Warbler.