O'Reilly logo

Metaprogramming Elixir by Chris McCord

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required