Search⌘ K
AI Features

To DSL or Not to DSL?

Explore the considerations for using a DSL in Elixir by examining when it simplifies or complicates your code. Understand how to weigh factors like natural macro expression, user complexity, and code injection through examples, including an Emailer library case study that contrasts DSL and non-DSL designs.

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.

The big three

Whenever trying to decide whether a DSL is a good fit, keep the following questions in mind:

  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 use
...

...