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.
Two near-identical functions that differ only in literal values combine into one with a parameter.
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.
If the variations are conceptually different operations, one parameterized function will accumulate flags and special cases — keep them separate then.
One canonical implementation; new variations are new parameter values, not new functions.
Parameterizing functions whose variations are conceptually different operations — the parameterized function accumulates flags and special cases that overwhelm the original simplicity.