Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Presentation: Ruby and the Art of Domain Specific Languages

Presentation: Ruby and the Art of Domain Specific Languages

Domain Specific Languages (DSL) are a popular topic (see InfoQ's extensive coverage on DSLs)  across all language communities.

In this presentation, Rich Kilmer looks at creating DSLs in Ruby. Next to the usual distinction between external DSLs (involve writing a grammar and a parser) and internal DSLs (piggyback on the host language's grammar and parser), he explains  useful terminology.

Rich distinguishes betwen an implicit and explicit styles - this deals with questions of language design. An example of an explicit DSL is this:
when_shopping do |store| :popcorn :soda, @soda_amount
An example for an implicit DSL is this:
when_shopping {
 buy :popcorn
 buy :soda
Both approaches have benefits and problems. One issue of explicit DSLs is the added token noise, eg. the formal block argument definition. As Rich explains, this noise can look confusing when domain experts are supposed to read and check the code written in the DSL. An implicit DSL looks cleaner - yet it has the problem that it's possible to have scoping problems or that it's unclear where the called functions or methods actually come from. Rich goes into more detail about the trade-offs of either approach and when to use which.

The talk is rounded off with Rich looking at a very long list of real world DSLs he has written over many years for work. This provides valuable real life experience from designing and working with these DSLs. Lessons include how designing a DSL can help uncover holes in specs, simply because code is less forgiving than prose.

Watch Rich Kilmer's Ruby and the Art of Domain Specific Languages.

Rate this Article