July 27, 2007 at 14:23 Tags Lisp , Programming , Ruby

The idea of Domain Specific Languages (DSL) has been lately brought into attention by the freshly popular programming language Ruby. In particular, the famed web framework Ruby On Rails, which is built as a DSL on top of Ruby has been a prime example.

What most people are not aware of, however, is that DSLs is just a new incarnation of the very old concept born in the world of Lisp called Metalinguistic Abstraction. It is a recurrent theme in the seminal MIT textbook, Structure and Interpretation of Computer Programs (SICP) that was written in 1985 to present general computer programming concepts using the Scheme language (member of the Lisp family).

Metalinguistic Abstraction is the process of solving programming problems by creating a new language that is better suited to tackle these problems. Unlike the traditional software engineering process of dividing problems to exactly defined subproblems and solving those subproblems, metalinguistic abstraction instructs the programmer to imagine a new programming language in which the solution of these problems can be expressed most naturally, and then implement this language.

While this sounds a bit detached, Rails actually provides a good, modern example of how such a concept can work. The designer of Rails asked himself "what language do I need to write web applications more naturally". He then went forward to implement this language on top of Ruby. Naturally, he could have created a completely new programming language. However, building it on top of an existing system provides several powerful benefits:

You don't need to craft a parser for the new language. You don't have to make up new syntax, just use the existing syntax of the language you're building on top of. Most importantly - since you are just building a layer on top of an existing programming language, all the facilities and power of this language are available to you, for free. This greatly enhances the immediate usefulness of the new DSL.

Ruby is a good language to build DSLs in, and Rails is a prime example of this. Ruby is better in this task than the other popular languages - Perl, Python, C++, Java, C#, etc. However, it is much inferior to Lisp. This is in no way to diminish Ruby's success or start a language war, I'm simply stating a fact. Lisp has some unique concepts that make metalinguistic abstraction natural, namely uniform syntax and macros.

Since metalinguistic abstraction is such a powerful programming technique, it is highly recommended for any programmer to learn Lisp (whether it is Common Lisp or Scheme doesn't really matter). Even if you'll never use it for any official project, just the act of learning it and understanding the programming techniques possible in it will surely expand your mind and make you a better programmer.