Split Variable

Symptom

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

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

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

Tradeoff

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

Relief

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

Trap

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