Domain Specific Languages

This is how a typical company works: A domain specialist (say a pension expert) builds a prototype in Excel/VBA. To make the prototype work for the whole company it is recoded as a pseudo Excel engine, codeded in PHP, with the prototype (Excel) expressions shoehorned into it. Or some variation thereof. Almost always, the domain specialist is replaced by or has to start working with a coder, where it would make much more sense to replace the domain specialists tool (Excel) with a better one, a DSL. And here is a couple of reasons why:

 A DSL drastically lowers the complexity of expressing domain knowledge in your code. 

 A DSL decouples what is expressed and how it is implemented. 

Let me examplify; implement “If you have been married for more than half the fiscal year…” given the domain knowledge: Dutch law mandates that you can get a divorce only after being marriage for at least a year.

In a generic language (given some suitable library) one could write: if (is_married_on($year, 6, 30)) reasoning that who has been married the middle day of the year, must have been been married for at least the first or the last half.

Apart from the hard to spot bugs in this code, it is hard to understand what constitutes being married more than half a year. Is it 183 days and 184 in a leap year? Being married the first three and last three months of the year?

Look at three examples in an imaginary predicate logic like DSL:

{is "married" | day $Y 30 6} ->
{sum #day "married" | year $Y} >= 183 ->
{sum #day "married" | year $Y} > {sum #day | year $Y}/2 ->

How easy it is for the domain expert to express things much more explicit and more importantly without involving a coder. A generic language would need a huge number of domain specific library call’s with extreme explicit naming and still would not get close to offering a flexible and explicit alternative. Besides, it is nice to use some explicit language now and than. (Please not it is hard to give a simple example for something that makes hard things easy.)

If you find that your company is implementing the same thing over and over, it should be easy and quick, but it is not, don’t hesitate, contact the experts, contact us.