ch39.md 1.2 KB

Chapter 39. Advice

The examples we have seen so far do not only show how macros can be implemented; they are also supposed to show good design of domain specific languages (DSL). In general a library that uses macros to good effect focuses on:

  1. Composability. It should be possible to combine different DSLs into a coherent program.
  2. Understandability. Hide the right amount of details but do not hide important aspects of your programs. For example, injecting temporary variables is almost always beneficial and arguably a large part of what drives the distinction between low level and high level programming. On the other hand, hiding control flow can make your programs more brittle. Beware of designs that focus on “single character” DSLs such as regular expressions and what strformat offers; these are inherently not scalable as single characters are hard to remember and it is not obvious how to arrive at a design where optional whitespace can be inserted for better readability.
  3. Documentation. Macros should be documented well. The performed transformations should be outlined and the design ideas behind the DSL should be documented.