Move Statements to Callers

Removes smells
Compare
Symptom
Human

A function whose body mixes its core responsibility with statements that genuinely vary per caller — different logging contexts, different post-processing, different metric labels.

Agent

The agent finds a function body whose statements vary by caller context — logging contexts, post-processing flags, metric labels baked into one body via branches.

Goal
Human

Statements that vary by caller move out of the function so each caller chooses its own setup or follow-up.

Agent

The function's body addresses one responsibility; callers express their differences at the call site.

Before the refactoring

function emit(line) {
log.write(line);
metrics.tick();
}

After the refactoring

function emit(line) { log.write(line); }
emit('startup');
metrics.tick();
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

The function's single responsibility is obscured by per-caller variations baked in; adding a new caller forces extending the function's branches.

Agent

Adding a new caller forces extending the function's branches; the agent must reason about which branch applies and verify branch coverage at every site.

Tradeoff
Human

If most callers want the moved statements, the change creates duplication — the inverse of Move Statements into Function is only an improvement when callers genuinely differ.

Agent

If most callers want the moved statements, the agent now sees duplicated boilerplate at every call site — the inverse smell.

Relief
Human

The function's body becomes about its single responsibility; callers express their differences directly.

Agent

The function's contract narrows to its single responsibility; callers express variation explicitly; the agent reasons about one body and one branch per caller.

Trap
Human

Pushing statements to callers when most callers want them anyway — creates duplication at every call site while the original function was perfectly clear.

Agent

Pushing statements to callers when most callers want them creates duplication the agent must keep in sync across every site — substitutes one smell for another.