Wednesday, January 19, 2011

Review of: DSLs in Action

Author: Debasish Ghosh
Publisher: Manning Publications
ISBN-10: 1935182455
ISBN-13: 978-1935182450

$44.99 (Manning publishing) 375 pgs.

Once you implement a domain model in your favorite programming language, it no longer speaks the dialect that the domain expert can understand. If your implementation doesn't conform exactly to the specifications you agreed on with the domain user there's no way it can be verified by the person who understands the domain rules.

DSLs in Action addresses this by suggesting a DSL-driven application development model. Design your domain APIs around the syntax and semantics that the domain user understands. Then, even during the development of the code base, the user can do incremental verifications of the domain rule implementations. If your code speaks the language of the domain, it becomes clearer to the person who develops it, to the one who maintains it, and to a nonprogrammer domain expert who understands the business.

You will learn how to design and implement DSLs using the modern languages Ruby, Groovy, Scala, Clojure and Java. In addition, discussions of the strengths and weaknesses of these languages when designing a DSL are included.

Admittedly, not everyone will be familiar with all the programming languages used to implement the DSL structures in this book so the author has included short reference cards (or cheat sheets) for the languages in the appendixes. More thorough references are provided to complete texts to supplement them. The source code for all examples in this book is available from Manning's website,

The author, Debasish Ghosh (@debasishg on Twitter), is the chief technology evangelist at Anshinsoft ( He's a senior member of the ACM and his blog is at Ruminations of a Programmer (

Summary of Contents
Part 1: Using DSLs
Chapter 1: Learning to Speak the Language of the Domain
What a DSL actually is and the benefits it can provide start this chapter. The structure of a DSL is covered. The chapter concludes by tying in appendix A and discussing what makes a well-designed abstraction.

Chapter 2: The DSL in the Wild
Here you create your first DSL using Java. Groovy is introduced to demonstrate how to make the DSL more Expressive. DSL implementation patterns are introduced and how to choose a DSL type is presented.

Chapter 3: DSL-driven Application Development
Integrating internal and external DSLs in an application is the main topic of this chapter. Once this topic is completed, error and exception management is discussed and performance optimization is covered.

Part 2: Implementing DSLs
Chapter 4: Internal DSL Implementation Patterns
The author demonstrates how to build a programmer's toolbox of architectural patterns that can be used to implement DSLs. The use of metaprogramming to aid in the construction is extensively covered.

Chapter 5: Internal DSL Design in Ruby, Groovy and Clojure
The running application typical of Manning books, in this case a stock trading processor, is introduced here. The initial implementation is in Ruby and then it is improved with Groovy. Clojure is introduced to demonstrate how one must think a little differently with this language. A discussion of the pitfalls of each of these languages concluded the chapter,

Chapter 6: Internal DSL Design in Scala
This chapter is dedicated to Scala to which the author gives a good introduction. Developing an internal DSL with Scala is then covered. A discussion of monadic structures rounds out the chapter.

Chapter 7: External DSL Implementation Artifacts
This chapter is dedicated to the tools used to generate an external DSL. Parsers are discussed along with ANTLR, the Eclipse Modeling Framework and Xtext.

Chapter 8: Designing External DSLs using Scala Parser Combinators
Beginning with a discussion of exactly what parser combinators are this chapter continues with the Scala parser combinator library. A discussion of packrat parsers follows and then a dive into Scala DSL design with the combinators finishes up.

Part 3: Future trends in DSL development
Chapter 9: DSL Design: Looking Forward
The main thrust of this chapter is to touch base on developing trends in the DSL world. DSL workbenches are canvassed. The important topic of DSL versioning and practices that you can adopt to ensure a smooth evolution of your DSL's syntax rounds out the book.

Not for beginners. At first this book comes at you so fast that it can seem overwhelming but hold on it does get better. Although this reviewer would not call this a 'Magnum Opus' it is as close as you get without being one. It becomes immediately clear that the author knows what he is doing and does this sort of thing everyday.

Ruby, Groovy, Clojure and Scala along with Java are used in the examples and this reviewer and the author are willing to bet that the reader is fluent in at least one of those languages. The good thing here, as the author says, is all of the code is understandable regardless of whether you have experience with one of them or not. It should also convince readers to do what they've said they were going to do for the last three years and learn a new programming language. One excellent side effect of so many languages in such a small space is that you will learn how each of them makes you think about and approach a problem differently.

The book contains excellent discussions of domain cognizance with topics such as accidental complexity and minimalism in coding followed with a great review/introduction of the differences, strengths and weaknesses of Internal DSLs versus External DSLs. There is even a chapter dedicated to designing external DSLs via Scala parser combinators.

It is an exhaustively wide and deep coverage of the subject. By the time you've finished reading the book, you'll have a thorough understanding of the concepts that you need to master in order to design domain abstractions that your users can understand and appreciate. This will bring much added business value to any project.

Five languages with no trivial examples all in one book, highly recommended.