BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

Presentation: Ruby and the Art of Domain Specific Languages

| by Werner Schuster on Feb 22, 2008. Estimated reading time: 1 minute | NOTICE: The next QCon is in San Francisco Nov 13-17, 2017. Join us!
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|
 store.buy :popcorn
 store.buy :soda, @soda_amount
end
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

Adoption Stage
Style

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
Community comments

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

Discuss

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


Recover your password...

Follow

Follow your favorite topics and editors

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

Like

More signal, less noise

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

Notifications

Stay up-to-date

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

BT