Why a domain specific language?
The worth of a programming language is its ablity to be used to express an algorithm or process in a way that
- Correctly implements the intended algorithm
- Is understandable and maintainable
It can be worth while creating a programming language specific to a particular problem domain if that language allows an algorithm, logic or process to be expressed more clearly in the code. Creating a domain specific language (DSL) involves risk and effort so it is only justified if the problem domain occurs often enough.
Goals of a good DSLThe design of a DSL consists of several core goals
- the domain specific language should be more expressive in its domain than a general programming language
- the domain specific language may exclude features normally provided by general programming languages so that it can be succinct for its domain
- the domain specific language can associate considerable internal logic/processing within the language terminals (symbols)
Some advantages:
- The close match of terms used by experts in the domain and grammar of the domain specific language means that those experts not only understand the meaning of the DSL code from its descriptive nature, but can also edit the DSL code with considerably better likelihood that the result of the code matches their intentions. That leads to a reduced defect/bug rate
- The concise nature of a good DSL improves productivity, maintainability, and communication between coders and users in the domain
- A good DSL allows data to be validated at the the domain scope, enhancing the runtime type checking on constructors
- A DSL has the flexibility to be run in an interpreter (script) or compiled to native code (executable). Running the DSL as a script allows the DSL interpreter to be embedded in a larger system written in a general programming language with DSL code possibly maintained as user defined extensions to the system.
Some disadvantages:
- A DSL requires a grammer, parser and runtime to be developed specifically for each DSL
- Version management of the DSL syntax becomes an important issue, as unlike a general programming language that provides enough general language features to compose almost any algorithm or process, a DSL in contrast may require extension beyond the limitations of its initial implementation in order to implement new algorithm, and so this introduces a maintenance dependency that the parser and runtime must be updated to an equal or higher version than the grammer of DSL code it is to execute
- A DSL may not be provided with a debugger, or other development tools due to the overhead or designing, implementing and maintaining those tools
- The performance of executed DSL code may be lower compared to OS native code