Why Metaprogramming Usually Makes Things Worse
Briefly

Why Metaprogramming Usually Makes Things Worse
"It is surprisingly hard to come up with a problem that truly cannot be solved without macros. I can recall only a handful of cases where they felt justified, and even then there were alternative solutions using ordinary language features. Most of the time, standard tools are enough. In practice, macros almost always make compilation slower. Build times go up, memory usage goes up, and suddenly your feedback loop is worse than it used to be. This alone should give pause."
"Sooner or later, every team runs into someone who has just discovered templates and is eager to apply metaprogramming everywhere. The intention is usually good. The outcome, more often than not, is not. In most real projects, macros and templates tend to create more problems than they solve. From here on, when I say macros or templates, I mean metaprogramming tools in a broad sense, not tied to any one language."
Developers often apply templates and macros enthusiastically, but such metaprogramming tools are seldom essential. Macros and templates span many languages and aim to automate repetitive or complex patterns, yet true problems that absolutely require them are rare. Many scenarios that seem to call for macros have ordinary-language alternatives or explicit code generation solutions. Macros typically slow compilation, increase memory use, and worsen developer feedback loops. Traditional code generation tools such as Protobuf already address many needs. Evaluate metaprogramming carefully and prefer standard features or explicit generation unless macros are clearly justified.
Read at Medium
Unable to calculate read time
[
|
]