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

Avoiding Common Pitfalls

As with any powerful tool, it’s easy to cut yourself. Throughout my Elixir experience, a few common mistakes have appeared that are easy to avoid in retrospect but can wreak havoc on your code base over time if ignored. Let’s find out ways to avoid getting caught in your own web of code generation.

Don’t use When You Can import

One of the most common mistakes newly minted metaprogrammers make is treating use as a way to mix in functions from other modules. This tempting idea conflates the concept of a mix-in from other languages, where you can include methods and functions from one module into another. In Elixir, this pitfall looks something like this.

Consider a StringTransforms module that defines a number of string ...

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