Consolidate Conditional Expression

Removes smells
Compare
Symptom
Human

Multiple conditions in sequence (or chained) leading to the same action — three guard clauses each returning 0, or three branches each running the same handler.

Agent

Multiple conditions in sequence lead to the same action; the agent must verify each branch leads to identical behavior and that adding a new condition won't accidentally diverge.

Goal
Human

Multiple conditions leading to the same action collapse into one named predicate.

Agent

The predicate lives at one named function the agent reads once; edits to the rule land at the function definition and propagate to every caller through reference.

Before the refactoring

if (employee.seniority < 2) return 0;
if (employee.monthsDisabled > 12) return 0;
if (employee.isPartTime) return 0;

After the refactoring

if (isIneligibleForBonus(employee)) return 0;
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

The shared rationale is invisible; adding a new condition with the same effect means touching N places; bugs hide where one of the branches diverges accidentally.

Agent

Adding or modifying any branch's behavior requires the agent to update every branch consistently; the shared rationale is invisible.

Tradeoff
Human

Combining conditions can hide their independent reasons — only consolidate when they truly express the same business rule.

Agent

If the conditions encode independent reasons (different rules that happen to produce the same outcome today), collapsing them hides distinctions the agent will need to re-split later.

Relief
Human

The shared rationale becomes visible and namable; new conditions extend one place instead of N.

Agent

The predicate lives at one named function; edits to the rule land at the definition and propagate through reference, removing the chance of one branch updating without the others.

Trap
Human

Combining conditions that look the same but encode independent reasons — the consolidated predicate hides distinct rules that need to evolve separately.

Agent

Collapsing conditions that look the same but encode independent rules hides distinctions the agent will need to re-split when one rule evolves differently from the others.