An opaque, convoluted, or hand-rolled algorithm where a clearer and well-known pattern (often library-provided) produces the same outputs.
The agent encounters a convoluted or hand-rolled algorithm where a well-known pattern produces the same outputs; reasoning about the bespoke version is expensive per read.
An opaque or convoluted algorithm gets replaced by a clearer one (often from a library or well-known pattern) that produces the same outputs.
The clearer algorithm replaces the bespoke; the agent reasons about a recognized pattern instead of reverse-engineering the original.
Before the refactoring
function found(people, n) {for (const p of people) if (p.name === n) return p;return null;}
After the refactoring
function found(people, n) {return people.find(p => p.name === n) ?? null;}
Future readers spend cycles decoding the bespoke version; correctness arguments stay local to this implementation; performance characteristics are unknown.
Every read of the bespoke algorithm pays the same decoding cost; the agent can't trust correctness without re-deriving the algorithm's invariants on every change.
Swapping algorithms wholesale forfeits behavioral safety — characterize the function with tests at every relevant input boundary before substituting.
Swapping algorithms wholesale forfeits behavioral safety unless every input boundary is characterized first; the agent that substitutes without characterization tests ships silent regressions.
Future maintainers read the well-known pattern instead of decoding the bespoke implementation; performance and correctness usually improve.
The replacement algorithm has a known cost profile and known invariants the agent reads from one well-named function; verification against the new algorithm pays one read of its definition instead of simulating the original's behavior step by step.
Swapping algorithms without characterizing every input boundary the original handled — including the off-by-one cases the original quietly got right that the substitute might get differently.
Substituting without characterization tests at every input boundary ships silent regressions where the original quietly handled edge cases the substitute handles differently.