Two or more near-identical functions that differ only in literal values — `tenPercentRaise(person)` and `fivePercentRaise(person)` differ only in 1.10 vs 1.05.
The agent finds near-identical functions differing only in literal values; consistency depends on every variant staying in sync.
Two near-identical functions that differ only in literal values combine into one with a parameter.
One canonical function with a parameter; the agent reasons about one body and verifies parameter values at call sites.
Before the refactoring
function tenPercentRaise(person) { person.salary *= 1.10; }function fivePercentRaise(person) { person.salary *= 1.05; }
After the refactoring
function raise(person, factor) { person.salary *= 1 + factor; }
Bug fixes must land in every variant; new variants are new functions; the shared shape isn't expressed anywhere.
Bug fixes must land in every variant; the agent must find and update each consistently or risk drift.
If the variations are conceptually different operations, one parameterized function will accumulate flags and special cases — keep them separate then.
If the variations encode conceptually different operations, the parameterized function grows flags and special cases the agent must thread through — worse than the original duplication.
One canonical implementation; new variations are new parameter values, not new functions.
One canonical implementation the agent reasons about; new variations are new parameter values, not new code paths.
Parameterizing functions whose variations are conceptually different operations — the parameterized function accumulates flags and special cases that overwhelm the original simplicity.
Parameterizing conceptually different operations accumulates flag-driven branches the agent must reason about — the function becomes a switch statement in disguise.