Macros

A macro is a rule to transfer one piece of code into another, usually expanding the code and writing out new code. Preprocessing code through macros is not a new idea. It was, and probably still is, very popular for C and C++. In fact, if you take a look at some of the source code for the GNU utilities for Linux, they are written almost entirely in macros. Macros are notorious as they are hard to understand and debug. For a long time, newly created languages such as Java and C#, did not support macros for exactly this reason.

That being said, even more recent languages such as Rust and Julia have brought the idea of macros back. These languages were influenced by the macros from the Scheme language, a dialect of Lisp. The difference between ...

Get Mastering JavaScript Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.