To DSL or Not to DSL?

So DSLs are pretty cool, huh? It’s tempting to solve all kinds of problems this way, but be careful. Many problems that seem like a good fit for a DSL are often better served by standard functions. Whenever I’m trying to decide whether a DSL is a good fit, I ask myself the following questions:

  1. Can the domain be expressed naturally by macros in Elixir’s syntax, such as HTML tags?

  2. Would a DSL cause the caller to think more or less about how to solve their problem?

  3. Should I require users of my library to have all kinds of code injected into their context?

The answers to these questions vary, and many times it’s a gray area. To help illustrate these points, let’s imagine a fictitious Emailer library that we would like to build. ...

Get Metaprogramming Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.