I recently came across some DSLs which had some defects. Let’s look at a sample I quickly hacked together with Xtext:[
Here are two recommendations I’d like to give when designing a textual DSL:
Don’t use uppercase letters in the keywords of your DSL, unless you either really like them. In the sample DSL, the keywords (Element, EndElement, Child, Endchild all start with an uppercase letter, which makes it cumbersome to edit the DSL script (you need to press the shift key a lot). Back in the days when we didn’t have syntax highlighting, UPPERCASE keywords made a lot of sense as they helped to draw a better distinction between the keywords, the variables and the constants (strings and numbers) of a program. Nowadays, it is hard to find an IDE which does not offer syntax highlighting, so this argument does not hold any more.
Do not use noisy begin…end syntax constructions. They do not increase readability of your DSL script and they add to the amount of code to be typed.
Here is an improved version of the DSL script: [
By removing the Endelement and Endchild keywords, we have improved readability a lot. Using lowercase keywords has lowered the effort you need to invest to key in the DSL script. And – honestly – don’t we all like to be lazy at times? After all, one of the goals of DSLs is to make your work easier and more efficient.
That being said, have a great weekend!