Leading a band——
Tamar, one of my good friends and a singer was telling me a story about the first time she led a band. She was singing Route 66, and after she got up on stage, she said:
Route 66 in E Flat
Drummer, I want a big boom after "get your kicks"
We're gonna run through it once, mess around,
come back in on the bridge and I wanna tag it on the end.
a one, a two, a one-two-three-four...
In 15 seconds, she was able to communicate to them (a band she’d never sang with) exactly how she wanted them to perform the song. It would have taken her half an hour to communicate the same thing to me, but she and they spoke the same language. It was a Domain Specific Language or DSL.
Examples in Software——
In software, you might have different domain specific languages, but the concept is the same. They are able to provide more concise, precise and quickly understandable representations within a domain.
Let’s look at a couple examples:
This is a domain specific language implemented in XML that many java and c# developers are familiar with. NAnt is used to build .net projects, below you’ll see a simple build file. Notice how all the first level constructs have to do 100% with the domain of building an application.
<project name="MyProject" default="build">
<solution solutionfile="MyProject.sln" configuration="Debug" outputdir="build"/>
<target name="test" depends="compile, refresh-books">
<arg value="MyProject.Tests.dll" />
<target name="build" depends="compile, test"/>
Active Records in Ruby on Rails
There is a lot of buzz right now around Ruby on Rails. One of the things that Rails does incredibly elegantly is it’s OR (object/relational) mapping.
This code just mapped the Recipe object to the recipes table in the database and whatever fields it has. It associates every recipe with a category, and every category with a list of recipes.
Again, the common pattern is that there is not a lot of code here that is not specific to the domain. Domain specific relationships like “belongs_to” and “has_many” are represented by top level constructs.
In trying to explain Language Workbenches and “intentional programming”, I often talk about the value of DSL’s, but it’s sometimes hard to come up with examples that someone will connect with. Here I gave a totally non-technical example, an xml based example and a ruby based example.
What examples of other types of Domain Specific Lanaguages can you think of?