Building Domain Specific Languages (DSL
) in Boo
by Oren Eini
leads the intermediate to advanced programmer through the process of building several DSLs in the Boo programming language. It is not an introduction to Boo, but rather it is assumed that the user is advanced enough so that picking up a new language is not an insurmountable prerequisite. A Boo tutorial and reference is provided in the appendix.
The writing style is inviting an informal. The first two paragraphs will immediately endear programmers to Oren Eini:
At first, there was the bit. And the bit shifted left, and the bit shifted right, and there was the byte. The byte grew into a word, and then into double word. And the developer saw the work and it was good. And the evening and the morning were the first day.
And on the next day, the developer came back to the work and couldn’t figure out what he was thinking last night, and spent the whole day figuring that out.
Oren chose to write about building DSLs in Boo specifically because of the excellent language-oriented programming
features available in the Boo programming language. This is not a book about the nuts and bolts of building a language from scratch. That would not truly be a treatise on DSLs as the purpose of DSLs is increased abstraction. That increased abstraction drives Oren’s craft. He makes no reservations about the fact that code maintainability and not performance is his primary concern.
This is a book about getting your feet wet and jumping right into building usable real-world DSLs. This book is immediately applicable to the work performed by hundreds of thousands of programmers every day. The DSLs presented in the book are pertinent to the work of enterprise developers. Thorough code samples of the fully functional DSLs are provided.
is Oren’s low-level implementation of a language factory. It is leveraged throughout the book. Sufficient detail into the design goals and implementation of the library are given so that it could be easily reproduced even if it were not freely available as open source. Rhino DSL is licensed under the BSD license. I have used it. It is wonderful and I see no reason to reinvent the wheel.
Testing, versioning, and creating IDEs to polish your DSLs are topics treated thoroughly. Oren teaches you how and when to version your DSL. He presents several strategies for versioning. He drives home the points that automated testing is not an option, it’s a requirement.
I found the chapter on creating an IDE invaluable. Oren recommends using Sharp Develop. It is freely distributable and allows you to build a stand-alone DSL editor to distribute as a part of your package. The chapter begins by demonstrating how to provide a good text editing experience with syntax highlighting and code completion and then moves on to advanced topics such as how to create visualizations to round out the editing experience. This task is made easier thanks to the ability to use the abstract syntax tree (AST) provided by the Boo Parser. Score another one for Boo!
Not all of Oren’s advice is about programming itself. He provides insights into the business-aspect of creating DSLs as well. The first emphasis box in the documentation chapter is titled “Ensure an initial positive impression.” The common-sense statements in this box provide polish to the book, much as he is trying to teach the reader how to provide polish to a DSL.
These sentences captured my interest intently:
A project that looks good is pleasant to use, easier to demo and in general easier to get funding for.
The first stage should be a very easy one, even if you have to design to enable that specifically.
How often as programmers do we neglect to create a good first-impression of our amazing products? The code is well-tested and flawless, but it takes another computer scientist of equal skill an hour to get anything working.
Oren’s blend of humor and common-sense advice makes the book a joy to read. His example code and discussion of abstract concepts will challenge you to become a better programmer. Oren brings you into his world, one where everything is done correctly. All code is maintainable, self-documenting, and easy-to-read.
If you are a .NET developer, I cannot encourage you enough to pick up this book. Oren’s thoughts are valuable even if you never write a DSL. The concepts of language-oriented programming are becoming more main-stream
, and this book is an excellent introduction that will open your eyes to the practical implications of language-oriented design.