When to Use Macros
In 1996, author Chuck Palahniuk released the novel “Fight Club”, which was later made into a movie. The so-called fight club in the story had a set of rules. The first rule of fight club was, "You don’t talk about fight club."
In a similar spirit, we introduce Macro Club. Macro Club has two rules, plus one exception. The first rule of Macro Club is Don’t Write Macros. Macros are complex, and they require you to think carefully about the interplay of macro expansion time and compile time. If you can write it as a function, think twice before using a macro.
The second rule of Macro Club is Write Macros If That Is the Only Way to Encapsulate a Pattern. All programming languages provide some way to encapsulate patterns, but ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access