Metaprogramming
Metaprogramming is the practice of using programs or language mechanisms to inspect, generate, transform, or reason about other programs or their representations.
Functional Design and Architecture: Examples in Haskell
Metaprogramming is the manipulation or generation of program representations to produce or transform code, often during compilation.
- How it is used
- Reduces structural boilerplate when generated abstractions can keep complex data manipulation concise.
- How deep it goes
- Defines compile-time code generation and its visibility trade-off without detailing compiler mechanics.
- Examples
- Illustrates generated Person lenses through makeLenses and composed field access.
- What you can do after
- Evaluate/understand when compile-time generation can improve expressiveness while obscuring emitted code.
Read how Functional Design and Architecture: Examples in Haskell explains metaprogramming →
The Joy of JavaScript
Metaprogramming is the practice of writing programs that inspect, generate, or modify other programs or their own structure.
- How it is used
- Automates repetitive work and separates cross-cutting concerns from core application behavior.
- How deep it goes
- Explains symbols, Proxy, Reflect, and decorators as static hooks or dynamic weaving, without detailing their complete APIs.
- Examples
- Uses logging, tracing, performance metrics, iteration, primitive conversion, spreading, and printing as behavioral examples.
- What you can do after
- Apply it via Symbols, Proxy, Reflect, and decorators to alter behavior while preserving cleaner interfaces.
Write Powerful Rust Macros
Metaprogramming is the practice of writing code that treats other code as data so it can manipulate or generate code or add capabilities.
- How it is used
- Positions metaprogramming as a practical Rust technique for generating code, reducing duplication, and extending ordinary programming tools.
- How deep it goes
- Defines code generation and compile-time expansion, then distinguishes declarative and procedural macros without implementing either internally.
- Examples
- Uses Deserialize, format!, dbg!, test attributes, assert_eq!, and generated code hidden within a small Rust program.
- What you can do after
- Evaluate/understand when Rust macros provide capabilities that functions and ordinary coding tools cannot provide.
Read how Write Powerful Rust Macros explains metaprogramming →
Related concepts
- macroused by · A macro is a named construct that expands or transforms source code, commands, or templates before or during execution.
- callbackuses · A callback is a function or other callable supplied to software for invocation later in response to a specified event, condition, or point in execution.
- reflectionuses · Reflection is a programming capability for inspecting or interacting with program types, members, values, or metadata dynamically at runtime.
- procedural macroincludes · A procedural macro is a Rust macro implemented as a program that transforms an input token stream into generated code during compilation.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


