Inline Variable

Removes smells
Compare
Symptom
Human

A local variable that's just a rename of its right-hand side — `const basePrice = order.basePrice;` — adding no domain meaning the original expression didn't already carry. The reader pays for a binding that returns no information, and small scopes accumulate redundant names that crowd out the meaningful variables.

Agent

A local variable whose name says the same thing as the expression bound to it; reading the variable name and reading the expression resolve to the same understanding. The agent pays for the binding lookup that returns no information not already implied by the expression at the use site, and the extra name competes for space.

Goal
Human

Single-use variables that just rename their right-hand side disappear; the expression speaks for itself. The reader's per read drops by the name-lookup hop the binding required, and of the scope rises as redundant names give way to the expressions they merely renamed.

Agent

Expressions sit at their use sites without an intervening binding; the agent reads the expression once instead of reading the variable name plus the binding's definition. The agent's per read drops by the size of the binding declaration, and count drops because no name-resolution hop intervenes between the use site and the expression's meaning.

Before the refactoring

const basePrice = order.basePrice;
return basePrice > 1000;

After the refactoring

return order.basePrice > 1000;
Example source: Illustrative example written for this site; the refactoring itself is catalogued in Martin Fowler's Refactoring (Addison-Wesley, 2018), see the chapter on A First Set of Refactorings.
Pressure
Human

Readers track an extra name for nothing; small scopes accumulate redundant references; the variable's existence implies meaning it doesn't have. The team's on edits touching the binding rises by one declaration to verify on every change, and reviewers grant the binding presumed meaning that isn't there.

Agent

The agent tracks an extra name in scope for no reasoning benefit; reference resolution becomes a tiny hop to a definition that adds nothing. The agent's on any edit touching the variable rises by one declaration to verify, and chained reads multiply the cost across every use site that resolves through the rebound name.

Tradeoff
Human

Inlining a name that did carry domain meaning costs readability — only inline when the expression is already self-explanatory. The team's can rise rather than drop if inlining strips a name that was load-bearing across multiple reads, because the original named concept now lives nowhere in the scope.

Agent

Inlining a variable that did carry domain meaning forces the agent to interpret the bare expression every time instead of reading the named concept. The agent's rises during the inline itself — every reference to the binding must be confirmed to use the inlined expression form, and any straggling reference becomes a regression.

Relief
Human

Less local clutter, fewer redundant names, smaller scopes to track. The team's drops because adding a new use of the expression doesn't require updating a binding's name, and reviewers focus on the meaning at the use site rather than reconciling the binding's name with the expression it merely renamed.

Agent

One fewer name in scope to resolve at every read; the agent loads the expression once at its single use site instead of paying the lookup hop from the variable to its definition. Token cost per edit drops because the binding declaration disappears, and contracts as the scope shrinks.

Trap
Human

Inlining a variable whose name did carry domain meaning — collapsing `const annualRate = 0.05` to bare `0.05` strips the named constant the reader needed. The of decoding what `0.05` means at every use site rises, and the cure adds by stripping the named domain concept the binding was holding.

Agent

Inlining a variable whose name carried a non-obvious meaning (a domain term, an intermediate result) forces the agent to re-derive the meaning of the expression at every site it appears. The agent's rises per read because the named concept now lives nowhere, and token cost multiplies across uses that would have resolved to the name.