DELAPARRA
Index
Color
NL
Category: Programming paradigms

Macro

Explained by Updated

What is Macro?

Macro: Code that runs at compile time to generate or transform other code before it is compiled/executed. A macro is code that runs before or during compilation to generate or transform other code. It lets you write a short instruction that expands into a larger piece of code. In C, macros are simple text substitution. In Rust, macros like println! and vec! work on the structure of code. Lisp macros are famously powerful, because Lisp code is itself data that macros can rewrite freely.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Macro

What should you keep in mind with Macro?

Macros remove repetitive code and can add new language features. The trade-off is readability and debugging, because the code that runs is not quite what you wrote. PHP and JavaScript have no compile-time macros, but code generators, Babel transforms and Laravel's runtime macro() method for extending classes fill a similar role. Use them where they remove real repetition, not to be clever.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with M

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.