Domain specific languages

Everyone active in de online industry probably has at least once edited their “hosts file”. Do you remember by heart what comes first the hostname or the IP address? I know I always forget, fortunately there is always an example in the file itself.

The hosts file is what is called a domain specific language or DSL for short. The hosts file is an instruction to the IP stack to resolve certain hostnames not via DNS but directly by a mapping.

DSL’s have had an important place in programming and their importance is rising. DSL can simplify programming and make systems more flexible by putting some part of the workings of a system outside code in a separate file. In the Java and .Net ecosystems we have seen many DLS’s, such as the web.xml, server.config, hibernate mapping files and spring configuration files.

Many of these examples take some part of the programming away from a general purpose language such as Java or C# and put the programming in some kind of XML. That is also where two of the major dangers lie of DSL’s. As a programmer you have to adopt and learn a new language. Second point DSL’s are by their nature limited in what you can do compared to a general assignment. I have yet have to come across a DSL where something simple as assignment can be done.

If you are developing both the DSL and the engine that processes the DSL, be very careful of DSL bloat. DSL should be limited in what you can do with them. Before you know you are writing a compiler, which is not a mundane task and often architecturally appealing but not very economical and practical. A good example that I have witnessed a couple of times is a web form generator. A simple xml or csv file drives the layout and processing of a webform. Nice idea until you start getting more and more requirements and end up writing a DSL with so many flags and options that the language is becoming equally complex to HTML itself. In fact HTML is one of the best form generating languages around. Xforms is an example of how difficult it is to write a DSL and get momentum in the developer community for using it.

I think it was Martin Fowler who started writing about DSL’s.

I checked the IP part comes before the host part in the hosts file. Bonus question: what is the windows path to the hosts file?

Advertisements

One Response to “Domain specific languages”

  1. Hans Says:

    C:\WINDOWS\system32\drivers\etc 😉

Comments are closed.


%d bloggers like this: