06
Mutable Data
Symptom
Data structures whose fields are reassigned across the codebase, with no clear owner of the mutation.
Goal
Mutation happens in one place behind a named function (or returns a new value), so the moment of change is clear.
Smellier version
const order = { total: 100 };
applyDiscount(order); // mutates total
addTax(order); // mutates totalFresher versionconst order = { total: 100 };
const final = addTax(applyDiscount(order));Savings
Bugs stop being 'who set this field?' and become local to the encapsulating method.
Note
Reasoning about state at any moment requires tracing every writer; concurrent code becomes a hazard area.