liveBook · Manning

Metaprogramming

Metaprogramming is the practice of using programs or language mechanisms to inspect, generate, transform, or reason about other programs or their representations.

How 3 Manning books explain it

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
Uses compile-time code generation as a design tool for expressing code that would otherwise need to be written explicitly.
How deep it goes
Defines abstract-code manipulation and compile-time generation, then cautions that generated output can be difficult to inspect.
What you can do after
Evaluate metaprogramming as a design tool while accounting for the difficulty of inspecting generated 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.

Read how The Joy of JavaScript explains metaprogramming →

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 →

Also covered in

What to know first

Related concepts

Questions about metaprogramming

What is metaprogramming?

Metaprogramming is the practice of using programs or language mechanisms to inspect, generate, transform, or reason about other programs or their representations.

Which Manning books explain metaprogramming?

Functional Design and Architecture: Examples in Haskell, The Joy of JavaScript and Write Powerful Rust Macros.

What should I know before learning metaprogramming?

Manning books that teach metaprogramming usually introduce template, domain-specific language, macro and pattern matching first.

What kinds of metaprogramming are there?

Kinds of metaprogramming include macro and template metaprogramming.

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.