IT lexicon › Programming › Metaprogramming

Metaprogramming

Programming På svenska → Updated: 2026-05-23

Code that generates, transforms or manipulates other code — at compile time (static) or at runtime (dynamic).

Spectrum: C macros (text substitution) → Rust/Scala macros (AST transformation) → Lisp macros (code = data, the strongest form) → C++ templates → Python decorators & __getattr__ → JS Proxy. Java annotations + reflection sit in their own category.

Good for boilerplate elimination (Serde, Pydantic, dataclasses), ORMs, mocking, frameworks. Cost: harder debugging, worse IDE support and stack traces, easy to overuse. Classic rule: write the code three times before you write the macro.

← Back to the lexicon