Domain Specific Lanaguage

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">
  <target name="clean">
    <delete failonerror="false">
        <include name="build/**"/>
        <include name="**/bin/**"/>
        <include name="**/obj/**"/>
  <target name="compile">
    <solution solutionfile="MyProject.sln" configuration="Debug" outputdir="build"/>
  <target name="test" depends="compile, refresh-books">
    <exec program="../tools/NUnit/TestRunner.exe">
      <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.

 class Recipe

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?


One Response to “Domain Specific Lanaguage”

  1. Greg Jahnke Says:

    Great examples Jeremy – I don’t know if you recall but we worked together in Cleveland for a couple days. We are doing great now and have a real nice test-first environment going with our developers.

    The one thing that I find hard is teaching other developers patterns . . . design patterns are a seperate language that unfortunately most developers that I work with do not understand. Most likely because they have never seen the problems that pattern solve. So my current struggle is how to be a better design patter teacher(language) in order to increase our velocity.

    It makes a huge difference when you can look at someone and say “Use a factory to create a command” without having to say anything else.

    I enjoy your site and check it regularly, though I haven’t seen any pictures of women lately, so I assume you have a girlfriend now :)