Domain Specific Languages

In this blog post I will give a brief introduction to Domain specific Languages (DSLs). For a more elaborate description, I recommend reading various resources available online as well as whole books on DSLs, listed at the bottom of this post.

Software languages

Software languages are meant for communicating instructions to machines by people. For this, a software language constitutes a system of notation for writing programs. Such a system is usually defined in the form of the language syntax and semantics. Syntax defines the form that programs can have. Semantics defines the meaning of the programs.

For example, there exist many programming languages that are widely used in developing software:

ruby logo

typescript logo

java logo

cpp logo

python logo

Domain specific languages

While general-purpose programming languages can in principle be used for developing any type of application (from web-based SaaS to embedded software), each domain-specific language is specialized in a particular application domain.

For example, the following DSLs are good for expressing machine tasks in their particular domains, but hardly can be used for building an arbitrary software application. MATLAB is useful for describing matrix calculations, but we hardly would use it for programming a web application. SQL is meant for querying databases, but we will not use it for programming a microcontroller.

graphviz logo

sql logo

html logo

maple logo

awk logo

tex logo

matlab logo

logo logo

The power of DSLs is in that they capture the essence of a particular domain in a concise, efficient manner. They focus on a specific domain and this makes them understandable to domain experts without requiring deep programming knowledge. As a result, we achieve two important benefits of using DSLs.

  1. Reuse of domain knowledge: DSLs embed domain-specific terms, structures, and processes, ensuring the knowledge is captured in a way that can be reused within the domain.

  2. Make domain experts part of the development process: with DSLs, domain experts — those who best understand the problems and processes — can interact with the language directly, creating solutions that are robust and reflective of actual needs.

Thus, the software development process becomes more efficient, faster-to-market and bug-free.

How DSLs work: everything is a model

The same as for software languages, a DSL consists of syntax and semantics. However, as DSLs are meant to be usable and useful for domain experts with different technical background, DSLs can have multiple notations (concrete syntax) and multiple meanings (semantics). For example, we might want to have both a textual notation (for the ease of editing and exchanging programs) and graphical notation (for the better overview and comprehension). As for the semantics, we might want to generate executable source code, documentation, and test scenarios — all from the same DSL program.

To implement such an approach, we follow model-driven engineering (MDE) and put a model of the DSL in the center:

model in center overview

The domain model defines the structure of the DSL, its concepts and relationships between them. Parsers, and editors offer various notations (visual and textual) and tools to create and edit models (DSL programs). Translators and interpreters define semantics of the DSL by mapping its models to the executable code or other machine artifacts.

For example, here is a screenshot of the state machine DSL implemented in JetBrains MPS:

mps screenshot

Here on the left we see two representations of a state machine model: a textual and a graphical. Both these representations are used to edit the actual (abstract) model behind. And on the right is the Gherkin test scenario generated from the state machine model. The following video demonstrates this example in action:

Conclusion

DSLs are more than just specialized languages. They are transformative tools that capture, express, and automate domain knowledge. With DSLs, we can model and transform domain knowledge in ways that are scalable, reusable, and aligned with specific industry needs. As the demand for efficient, specialized software grows, DSLs offer a powerful solution to bridge the gap between domain expertise and technology.

Do you think a DSL can be useful in your context? We recommend to take these four considerations into account.

  1. Is there a real domain problem? Do you see that the problem that you want to solve appears from time to time and can happen on different occasions? Otherwise, if it is an isolated case then you might well solve it once using a general-purpose programming language.

  2. Do you need subject matter experts (domain experts) to be closely involved in the development of the software system? DSLs can incorporate subject matter experts, who are less knowledgable about the programming technology, in the development pipeline, leveraging their valuable domain knowledge in a consistent machine-ready form.

  3. Do you see consistency in your domain structure and logic? In other words, does your domain look like a language to you? Then wrapping it into the form of an actual software language will capture this implicit knowledge and will free your mind for more interesting work.

  4. Get F1RE involved. At F1RE we specialize in the development and adoptation of DSLs for various types of industries and we will be happy to look together into your case!

About Ulyana Tikhonova

I am a Model Driven Software Engineer at F1RE, since April 2024. I am a big fan of domain-specific languages (DSLs) and model-driven approach. I did my PhD on the semantics of DSLs and had worked with model-based testing on an industrial scale.

You can contact me at ulyana@f1re.io.