Friday, February 25, 2011

A gem on DSL syntax from the book : DSLs in Boo: Domain-Specific Languages in .NET

The reason why I fell in love with programming in the first place was the sheer quality of the information available. Compare this to say Telecom engineering where high quality material is few and hard to find. This book is just another fine example of the quality of content created for programmers.

Here are just some of the things relevant to DSL programming in general that I found intriguing in just a few pages of the book:

Gems on the syntax of the DSL: 
It is going to be an iterative process. There are no two ways about it. But like all things programming there are good and sloppy ways of going about it.

1.) A good way to come up with the syntax is to start with pretending your DSL is in plain English and write it down. e.g.
If Book Is Available then Buy it.

The syntax should cover a single scenario. You cannot imagine all the scenarios into a single syntax sample. 

2.)Now simplify the syntax sample, indenting it and breaking it into lines.g.:
if Book Is Available
    then buy book

3.)Then use your possible syntax toolbelt (that is things that are easily expressible in internal DSLs) to arrive at the final result e.g.:
if Book.IsAvailable:
    Buy

Try another scenario, iterate.
Also it is a good idea not to let the technical implementation details leak into the DSL syntax.
Also, I could have said Buy Book but rather since we check Book to be available it is clear (and less technical noisy) if we just say Buy.

There is soooo much more information packed in the book.
Disclaimer: This post is based on my understanding of the content in the book.


No comments:

Post a Comment