Sheerpower Logo

Macros vs. Blueprints: How to Choose


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

  1. Constants / Short Aliases → Macro
    macro MAX = 500
  2. Logging / Tracing → Macro
    macro trace = print "TRACE [[msg=ok]]" @trace (msg="starting…")
  3. CRUD Handlers per Entity → Blueprint
    blueprint crud print "read_[[placeholder]]" print "validate_[[placeholder]]" print "store_[[placeholder]]" end blueprint %generate crud with customer, client, employee
  4. 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)
Hide Description

    

       


      

Enter or modify the code below, and then click on RUN

Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use.