Replace Parameter with Query

Removes smells
Symptom

A function that takes a parameter the caller computed from data already available to the function — `discounted(order, basePrice, level)` where the function can compute basePrice and level itself.

Goal

When a function can compute its own answer from already-available state, callers don't have to pre-compute it.

Before the refactoring

const basePrice = order.qty * order.itemPrice;
const level = discountLevel(order);
const final = discounted(order, basePrice, level);

After the refactoring

const final = discounted(order); // computes basePrice and level itself
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure

Every caller pays the homework cost; signatures inflate with values the function can derive; the duplication of derivation logic scatters.

Tradeoff

If the query has side effects or is expensive, passing the value is genuinely better — only replace when the query is pure and cheap.

Relief

Signatures shrink; consumers stop doing the function's homework.

Trap

Replacing parameters with queries when the query is expensive or has side effects — multiplies cost and introduces hidden coupling.