Remove Flag Argument

Removes smells
Compare
Symptom
Human

A function with a boolean (or enum) flag parameter that dispatches to different internal behaviors — `setDimension('height', value)` vs `setDimension('width', value)`.

Agent

A function with a flag parameter that dispatches to different internal behaviors; the agent must trace the flag's value through the body to verify which branch any call exercises.

Goal
Human

Each flag value becomes its own well-named function; callers say what they mean rather than passing booleans.

Agent

Each flag value becomes a named function; the agent reads call sites as direct invocations of the intended behavior.

Before the refactoring

function setDimension(name, value) {
if (name === 'height') { /* ... */ }
else if (name === 'width') { /* ... */ }
}

After the refactoring

function setHeight(value) { /* ... */ }
function setWidth(value) { /* ... */ }
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

Call sites must remember the flag's meaning; the function's body is a switch the agent reads through to find each branch; new flag values touch one body that handles many concerns.

Agent

The agent must reason about flag values at every call site; the function's body conflates multiple concerns the agent must mentally split.

Tradeoff
Human

Two replacement functions with similar bodies introduce duplication — pair this with Extract Function for shared internals.

Agent

If the branches share substantial body, splitting produces duplication the agent must keep in sync; pair this with Extract Function for shared internals.

Relief
Human

Call sites read fluently; new variations land as new functions instead of new switch cases.

Agent

Each variant becomes its own function with one signature; call sites name the intent directly, and the agent does not track a flag value through the function body to predict which branch runs.

Trap
Human

Splitting flag-dispatched functions whose branches are mostly shared body — produces N functions with N copies of the same body, inverting the original abstraction.

Agent

Splitting flag-dispatched functions without extracting shared body creates N copies of the same logic the agent must keep in sync — the cure becomes the duplication smell.