O'Reilly logo

Programming Elixir by Dave Thomas

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

Chapter 20Macros and Code Evaluation

Have you ever felt frustrated that a language didn’t have just the right feature for some code you were writing? Or have you found yourself repeating chunks of code that weren’t amenable to factoring into functions? Or have you just wished you could program closer to your problem domain?

If so, then you’ll love this chapter.

But, before we get into the details, here’s a warning: macros can easily make your code harder to understand, because you’re essentially rewriting parts of the language. For that reason, never use a macro when you could use a function. Let’s repeat that:

Recipe 1Never use a macro when you can use a function.

In fact, you’ll probably not write a macro in regular application code. But ...

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