Saturday, March 29, 2008

Magical DSL's

DSL's are great. But they're not magic. And they're not new.
They're everywhere and been that way for a long time.

HTML is a DSL.

Python is a DSL.

The Unix shell and command-line "wiring" syntax is a sort of DSL for the orchestration of program execution.

A program is a DSL. Take the 'ls' program, for example. A DSL? How so? Is it because it was made with Ruby? It WASN'T made with Ruby?!?! How so? How can 'ls' be a DSL? Easy. The DSL it provides is composed of it's own name 'ls' plus the set of invocation arguments it supports. So 'ls -la' means something different than 'ls -latr'. Those are just three words (or phrase permutations) that are expressable using this DSL. If it's a DSL then what is the domain? The domain (the D in the DSL) is a file system. The language (the L in the DSL) is for expressing something about files on a file system. Or rather, for expressing some query you have about files on a file system. Either way, it's not magic. And not new.

The configuration file content read by your programs also act as a DSL. The domain? The domain of your specific program's behavior, of course.

An API is a DSL. API's have the rather useful but unsexy and seemingly overlooked quality of being a way to create DSL's out of what is otherwise a general purpose programming language. So you start with a general language at the bottom (C, Java, Python, whatever), then on top of that build another language which is more specific to the problem you're trying to solve, or idea you're trying to convey. That top layer is the API.

English is a DSL.
French is a DSL. Though the domain is almost exactly the same as English. Not exactly, but pretty close. There's no law that says you can't have multiple completely separate and distinct DSL's that exist, that all apply to the same domain. They just treat that domain a little bit differently, by having different qualities or strengths.

Algebraic notation is a DSL:
f(x) = x ^ 2
By the way, this DSL was created BEFORE Ruby. I know, I know... Mats, what you say?!?!

Music notation is a DSL.

If there were a language for describing or casting magic spells that too would be a DSL. And it would be the only DSL that might justify being treated as if it were magical. :)

All of the above are DSL's.

If a DSL is any syntax or linguistic protocol used for doing something or expressing something, then why all the fuss? We've had these and known about them for years. I'm not talking a few years. Not even a decade. I'm talking thousands of years, perhaps millions, depending on exactly how inclusive you want the definition to be. I'm sure we could make a reasonable case for Egyptian hieroglyphics being a DSL, and the grunting of Neanderthal cavemen.

One last point. Yes, I know you like Ruby. And I know you like Lisp. I see the admirable qualities of both those languages, and they're shared by other general purpose programming languages as well. But please, don't think they enable you alone to make DSL's, or that you can only create them using those languages. It's been done without them. It's being done without them. It's been done before them. It'll be done again, without them, I suspect, after they're forgotten and we've all moved on to the next shiny language that perhaps hasn't been invented yet. It's been done. Been there. Did it. Got the T-shirt.

Wake up. Get over it. DSL's are not magical. And they're very old. Move along folks. Nothings to see here. The next shiny hype-able meme is just around the corner, in the hallway to your left. Just follow the signs. But no flash pictures please.

------------------

By the way, if you're a language geek you may want to check out a short piece of creative writing of mine, called The Suggestions System. Here's the link to it on my other blog:
http://grograma.blogspot.com/2007/05/suggestions-system.html