Split Variable

Compare
Symptom
Human

A single variable (often named `temp`, `result`, `value`) reassigned multiple times to hold conceptually distinct values — perimeter, then area; current iteration result, then accumulator.

Agent

The agent finds a variable reassigned with values of conceptually different types or domains; reasoning about any expression involving it requires knowing which role is currently active.

Goal
Human

Each variable has one role; reassignment patterns reflect distinct purposes rather than reused storage.

Agent

Each variable holds one role with a stable name; the agent reasons about names without tracking reassignment timeline.

Before the refactoring

let temp = 2 * (height + width);
console.log(temp);
temp = height * width;
console.log(temp);

After the refactoring

const perimeter = 2 * (height + width);
console.log(perimeter);
const area = height * width;
console.log(area);
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

The reader must track which role the variable currently holds; bugs hide where one role's update accidentally clobbers another; refactoring either use is impossible without disentangling.

Agent

The agent must trace through reassignments to know what any reference currently means; type-narrowing in unions becomes guesswork at every read site.

Tradeoff
Human

If the two uses were actually coupled — shared init or synchronized update — splitting them invites drift the single mutation kept in sync.

Agent

If the two uses were actually coupled (shared init, synchronized update), splitting forces the agent to re-derive the coupling across two variables.

Relief
Human

Names match purpose; the type system can narrow each role; refactoring each use becomes local.

Agent

The agent reasons about each variable as a stable name; the type system can narrow each role; each use becomes independently refactorable.

Trap
Human

Splitting variables whose uses were genuinely coupled — accumulator that depends on a previous-iteration version of itself — fragments coherent state into separate variables that have to re-establish the coupling.

Agent

Splitting variables whose uses genuinely shared state forces the agent to re-establish the coupling outside the variable, complicating the original logic.