Macros vs. Blueprints: How to Choose
Both features reduce repetition. The difference is scope and output:
macros expand inline; blueprints generate full blocks per argument. This
guide helps you decide quickly and confidently.
Quick Decision Checklist
- One place, many uses, tiny snippet? Use a macro.
- Same module repeated per entity (N copies)? Use a blueprint.
- Need inheritance/composition of templates? Blueprint (extends/prepends).
- Need simple constants or logging wrappers? Macro.
- Need case‑formatted or sequential names? Blueprint (formatting & sequences).
Comparison Table
| Aspect |
Macros |
Blueprints |
Best Use |
| Expansion |
Inline at each @macro |
Generates one block per argument via %generate |
Macros: small inserts Blueprints: full modules |
| Typical Size |
1–10 lines |
10+ lines |
Use size as a heuristic |
| Param Handling |
Placeholders with defaults |
Placeholders, .lcase/.ucase/.ccase, sequences |
Blueprints for complex naming patterns |
| Composition |
Can call other macros |
extends and prepends |
Blueprints for layered templates |
| Copies Emitted |
One expansion per use |
N copies (one per argument) |
Prefer macros to avoid duplication when possible |
Patterns and Examples
-
Constants / Short Aliases → Macro
macro MAX = 500
-
Logging / Tracing → Macro
macro trace = print "TRACE [[msg=ok]]"
@trace (msg="starting…")
-
CRUD Handlers per Entity → Blueprint
blueprint crud
print "read_[[placeholder]]"
print "validate_[[placeholder]]"
print "store_[[placeholder]]"
end blueprint
%generate crud with customer, client, employee
-
Composable Pipelines → Blueprint (extends/prepends)
blueprint base
print "init_[[placeholder]]"
end blueprint
blueprint plus extends base
print "work_[[placeholder]]"
end blueprint
%generate plus with order
Maintainability Tips
- Prefer macros for tiny logic to avoid code bloat.
- Prefer blueprints when multiple entities require identical
structure—consistency beats copy‑paste.
- Use
%expand on/off during validation to inspect generated code.
Summary: If you need many uniform copies, pick
blueprints. If you need concise, reusable inserts, pick
macros. When in doubt, start with a macro; graduate to a blueprint
as the template grows and needs composition.
(Show/Hide Macros vs Blueprint Takeaways)
Macros vs Blueprint Takeaways
- Size & repetition are the top signals.
- Blueprints scale with entities; macros scale with call sites.
- Composition needs → Blueprints; constants/logging → Macros.