Replace Query with Parameter

Symptom

A function that internally reads from a query — global state, singleton, instance field — instead of receiving the value as a 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 refactoring

function rebate(order, rate) {
return order.total * rate;
}
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure

The function isn't testable in isolation; its dependencies are hidden in the body; pure-function reasoning is blocked.

Tradeoff

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.

Relief

The function becomes testable in isolation; its dependencies are visible in its signature; pure-function reasoning becomes possible.

Trap

Pushing every internal query out to parameters — including ones that read from stable, well-encapsulated state — bloats signatures with values that didn't need to be explicit.