Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use a Domain Specific Language? [closed]

I would like some practical guidance on when I should use a Domain Specific Language. I have found resources about advantages and disadvantages, but what kind of project would warrant its use?

It seems like there is a big investment in time to create and maintain a DSL, so in what application space would I get a productivity return on my time investment?

Edit: It seems the most common use of DSL is for file formats for persisting data state, what about using a DSL for program logic and structure(perhaps code generation)? When is this feasible?

Edit #2 I am mainly asking about when is creating a specific DSL worthwhile. Of course we should use existing DSLs as much as possible to save time.

like image 592
Kekoa Avatar asked Jun 16 '09 18:06

Kekoa


People also ask

When would you use DSL?

Firstly, I would use a DSL when the problem domain your developing against is a widely well known domain, and some business experts of that domain have already went through great lengths to build such a DSL so that you wouldn't have to go through the lengths yourself to solve all the problems they have already figured ...

What is the purpose of domain-specific language?

A domain-specific language is created specifically to solve problems in a particular domain and is not intended to be able to solve problems outside of it (although that may be technically possible). In contrast, general-purpose languages are created to solve problems in many domains.

What is an example of a DSL?

A good example of a DSL is HTML. It is a language for the web application domain. It can't be used for, say, number crunching, but it is clear how widely used HTML is on the web. A GPL creator does not know where the language might be used or the problems the user intends to solve with it.

What is domain-specific language?

A Domain-Specific Language (DSL) is a computer language that's targeted to a particular kind of problem, rather than a general purpose language that's aimed at any kind of software problem. Domain-specific languages have been talked about, and used for almost as long as computing has been done.


2 Answers

There are very few good reasons for creating yet another DSL. The world is fat with special-purpose languages.

Think along with these lines.

  1. Solve the problem with a general-purpose language such as Python, Java, C++.. whatever.

  2. Optimize that solution to factor out the common features and build a really nice, really elegant, really extensible class library.

  3. Optimize that class library to emphasize "orthogonality". Make sure all features work well together, without any problems.

  4. If you need simplification of the syntax only, create a scripting wrapper around your nice class library. This is your DSL. For Python, this is easy -- it's already a dynamic language. For Java, there are things you can leverage. For C++ it can be a bit of work to build this flexible scripting environment.

  5. If you still need further optimization, consider writing a compiler for your DSL.

like image 175
S.Lott Avatar answered Oct 03 '22 11:10

S.Lott


The ACM Computing Surveys article When and How to Develop Domain-Specific Languages provides advice on just this topic, as does Martin Fowler's 2010 book Domain-Specific Languages.

like image 33
Peter S. Housel Avatar answered Oct 03 '22 10:10

Peter S. Housel