Domain-Specific Languages Book Review
Martin Fowler is the Chief Scientist at technology consulting firm Thoughtworks, and author of some of the most information-rich books in the field of computing today. He is also an author who takes his time when writing about subjects that deeply interest him. How does his latest book compare to his previous titles? Read on to find out.Using mostly Java and C# (with an occasional Ruby snippet), Martin demonstrates DSL principles with clarity and precision. He relays his findings not from an ivory tower but from one computer language enthusiast to another. In the opening chapter, Fowler even uses the example of a Gothic castle's secret compartment security system instead of the typical 'modern day' state machine event trigger because "When I start to write, I need to swiftly explain what it is I'm writing about."
The book moves from Gothic castle security systems to DSL life-cycles and their roles in the enterprise in chapter 2, followed by implementing DSL's in chapter 3 that includes considerations for DSL architecture, parsers, macros, grammars, syntax and semantics. Chapters 4, 5 and 6 cover implementing internal and external DSL's and deciding on which to use depending on such characteristics as domain expertise, cost and learning curve. Chapter 7, 8 and 9 conclude the first part of the book by examining alternative computational models, code generation and language workbenches (schema definition languages, meta-models, source and projectional editing and the various tools that can be used such as MetaCase, Xtext and JetBrain's MPS).
Part 2 of the book applies some of the theory discussed in Part 1 to more specific working examples, starting off with a look at existing DSL's such as CSS, Graphviz, JMock, XAML and others. The chapters that follow explore the semantic model, symbol table, context variable, construction builder, macro and notification. Part 3 takes a look at external DSL topics, ranging from syntax-directed translation, Backus-Naur Form (BNF), tree construction, embedded translation and interpretation, foreign code, alternate tokenization, nested operator expression and newline separators. Several chapters in this section of the book on DSL parsers were written by co-author Rebecca Parsons. Part 4 covers various internal DSL (Ruby on Rails is an internal DSL, for example) topics including method chaining, object scoping, literal lists and maps, dynamic reception, textural polishing and literal extension. Part 5 on alternative computation models spans decision tables, dependency networks and state machines. The final part covers various aspects of code generation, including transformer, templates, model-aware and model ignorant generation.
Thanks to the success of Ruby and Ruby on Rails, interest in DSL's is especially high and growing - DSL-based testing tools like RSpec and Cucumber come to mine. DSL's authored in Java and .NET are also on the rise for the reasons that Martin suggests in his book.
After reading Domain-Specific Languages, the task of creating my own DSL isn't as scary or arduous as I feared. The book also gave me a much deeper appreciation for the DSL's I call upon for my own projects and inspires me to look for opportunities in today's computing landscape where DSL's could hasten resolution to a specific problem. Anyone who is working with a DSL and would like to learn more about what is happening under the covers or is even considering creating their own DSL or extending an existing one, Domain-Specific Languages offers an excellent foundation to pursue such an education.
Fowler's UML Distilled, Refactoring and Continuous Integration are books that helped define those potent computing aspects, and Domain-Specific Languages will likely do the same for the DSL category.
Title: Domain-Specific Languages Author: Martin Fowler with Rebecca Parsons Publisher: Addison-Wesley ISBN: 978-0321712943 Pages: 640 Price: $54.99