Noisy DSLs
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.
By the way, if you need help designing a DSL with Xtext - I and the entire Xtext team are happy to assist you. Just drop me a line (peter at itemis dot com) or hop on to our professional support site
From http://www.peterfriese.de/
Peter Friese is a software architect with itemis. He is a committer for the open source projects openArchitectureWare, Eclipse Modeling, FindBugs, and AndroMDA. As a software engineer and software architect, Peter has worked on a variety of industry projects in different domains such as banking, aerospace and transport. He is a regular speaker at various conferences and has authored a number of articles on topics like Eclipse, Spring, and model-driven software development. He can be contacted at peter.friese@itemis.de. Peter is a DZone MVB and is not an employee of DZone and has posted 13 posts at DZone.
- Login or register to post comments
- 552 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)









