59
Replace Query with Parameter
Goal
A function that reads from a query (global, singleton, instance state) instead accepts the value as a parameter and becomes referentially transparent.
Before the refactoring
function rebate(order) {
return order.total * currency().rate;
}After the refactoringfunction rebate(order, rate) {
return order.total * rate;
}Savings
The function becomes testable in isolation; its dependencies are visible in its signature; pure-function reasoning becomes possible.
Note
Passing the value pushes the responsibility onto callers; for many call sites, signatures grow noisily — prefer this when the query touches global or volatile state.