Metaprogramming
Metaprogramming writes code that manipulates the program's own structure, generating, modifying, or analyzing code at compile time or runtime.
Purpose
Code that generates code, raising the abstraction level and reducing boilerplate.
Mechanism
Compile time: macros (Rust/C), templates (C++), annotation processing (Java). Runtime: reflection (Java/Python), eval, Proxy (JS). Ruby implements many DSLs via metaprogramming.
Use cases
- Code generation
- Reflection
- DSL