Domain Specific Languages

I’ve just finished reading Martin Fowler’s Domain specific Languages. I’ve come away very impressed. The book’s subtitle isn’t “Computer Science for the working coder” but it may as well be. It covers a variety of topics related to parsing and code generation. Most of these I had heard of before but here they get given a thorough coverage.

One of the best features of the book is the style of writing. It’s part overview, part reference. Throughout, Fowler uses humour well to raise it from the level of a dry academic tome. The main example that runs throughout is a state machine for gothic mansion security systems.

Many of the patterns described (like BNF or Expression Builder) are things that I had come across before. Yet they’re fleshed out fully here, often with nuances you didn’t think about. For example, I first came across Expression Builder in Josh Bloch’s Effective Java. Here, it’s given a clear idea of where to and not to to use it. Plus plenty of code examples to illustrate.

But what really stood out for me was the section on external DSL’s. I’ve written my share of ad-hoc configuration file parsers, but using a proper parser generator has always seemed like a bit too much effort. Here, the basics are clearly shown (most of the examples use ANTLR) and it has suddenly opened up to me quite how simple it can be. Lovely! I can’t wait to find out a project to try it all out on.

What’s not so good? Not that much. Because of my background, I was a little irritated to see the lack of HTML escaping in the templating example. The main problem for most people might be the languages used for the examples: Java; C# and Ruby. Whilst it’s all fairly readable, you may have to bone up a little first if you’re less familiar. Fowler references other languages like Lisp, but acknowledges he’s not an expert there. Personally I enjoyed learning bits of C#—for example the Parse Tree Manipulation chapter was an eye opener.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s