BT

Presentation: Ruby and the Art of Domain Specific Languages

by Werner Schuster on Feb 22, 2008 | NOTICE: The next QCon is in London Mar 2-6, 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.

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

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT