Replace Query with Parameter

Compare
Symptom
Human

A function that internally reads from a query — global state, singleton, instance field — instead of receiving the value as a parameter.

Agent

A function reads from a query (global, singleton, instance state) instead of accepting the value as a parameter; the agent reasoning about it must model the query's state.

Goal
Human

A function that reads from a query (global, singleton, instance state) instead accepts the value as a parameter and becomes referentially transparent.

Agent

Dependencies are visible in the signature; the agent reasons about the function as a pure transformation of its inputs.

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
Human

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

Agent

The agent cannot test or compose the function without reproducing the query's state; reasoning about side effects requires modeling global timing.

Tradeoff
Human

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.

Agent

Pushing every internal query to a parameter bloats signatures the agent must thread through call sites — appropriate only for queries that touch global or volatile state.

Relief
Human

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

Agent

The agent reasons about pure transformations; tests target the function in isolation; signatures document dependencies.

Trap
Human

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.

Agent

Externalizing every internal query — including ones reading stable encapsulated state — bloats signatures the agent must thread through every call site for marginal isolation benefit.