Preparatory Refactoring: Make the Change Easy

Preparatory Refactoring: Make the Change Easy

Kent Beck's maxim names a deliberate move; this piece separates it from in-passing cleanup. The unlock-line scope test, prep-first commit ordering, and the label-laundering failure mode to watch for.

Kent Beck's maxim — "for each desired change, make the change easy (warning: this may be hard), then make the easy change" — describes a specific move: reshaping code on purpose to serve one upcoming change. This article separates that move from in-passing cleanup. One signal is a feature that requires touching many scattered places for what is conceptually one change. The scope test is an unlock line: preparation includes exactly the reshaping that makes the change easy, nothing beyond it, landed first as its own commits so the feature diff that follows reads as small as it conceptually is.

The maxim and the move it names

Kent Beck's formulation, as quoted in Martin Fowler's worked example of preparatory refactoring and worth quoting exactly: "for each desired change, make the change easy (warning: this may be hard), then make the easy change." The sentence names two separate moves and insists on their order — reshape the code first, then make the change that reshaping was for.

This is not the same activity as the boy-scout habit of leaving code slightly better than you found it. Boy-scout cleanup improves whatever is nearby, in passing, without a specific destination in mind. Preparatory refactoring is different in intent: it reshapes the code on purpose, toward a specific upcoming change, and stops once that change is easy. The two look similar in the moment — both are refactoring commits, both preserve behavior — but one is opportunistic and the other is targeted.

The parenthetical is the honest part of the maxim, and it is easy to read past. "This may be hard" concedes that making the change easy is not always cheap: the preparation can take more effort than the easy change that follows it. That is not a smell indicating something has gone wrong; it is the point. The bet is that total effort — preparation plus the eventual change — comes out lower than forcing the change into code that actively resists it; Martin Fowler reports that when he can spot how to do a preparatory refactoring, "it results in a faster and less-stressful programming experience."

Recognizing the signal

A clear signal that preparation is warranted: a feature that requires touching many scattered places across the codebase for what is, conceptually, one single change. If adding one new case means editing a dozen files that each encode a piece of the same decision, the scatter itself is diagnostic — the code's current shape disagrees with the shape the change wants.

A useful thought experiment sharpens this into something actionable: "this would be a three-line diff if the code were shaped like X." When X can actually be named — a specific data structure, a specific seam, a specific place where the variation could live in one spot instead of a dozen — preparation has a concrete target rather than a vague sense that things could be better.

Effort disproportion is the practical tell. When a feature that sounds small in one sentence is estimated as large in points or days, that mismatch can be a shape problem rather than a size problem. In that case the feature genuinely is small; the code just is not shaped to receive it cheaply yet.

This distinction matters for how the work gets planned, not just how it gets done. A feature that estimates large because it is genuinely large needs no special handling — the estimate is honest. A feature that estimates large because the code fights it is a different situation entirely, and conflating the two invites the same mistake: the team ships the awkward, oversized diff the code shape demanded, the underlying friction stays unaddressed, and the next feature that touches the same area pays the identical tax again.

Scoping the preparation

The unlock line is the scope boundary that keeps preparation from drifting: preparation includes exactly the reshaping that makes the intended change easy, and nothing past that point. It is tempting, once inside the code, to keep improving — but every improvement beyond the unlock line is a different kind of work wearing the same commit label.

Preparation should land first, as its own behavior-preserving commits or its own pull request, ahead of the feature it enables. Once it has landed, the feature diff that follows reads as small as it conceptually is — a reviewer looking at the feature commit sees exactly the new behavior, in code already shaped to hold it, rather than a change tangled together with the reshaping that made it possible.

There is a de-risking benefit that is easy to underweight: a preparation PR merged independently, before the feature lands, protects the investment even if plans change. If the feature gets descoped or delayed after preparation merges, the codebase keeps a genuine structural improvement instead of holding a stale branch that represents work nobody finished.

The honesty check

Preparation exists to serve one specific change — that is the whole justification for doing it now rather than as a separate initiative. Improvements that fall beyond the unlock line belong to boy-scout territory, or to a noted-for-later list, and folding them into the preparation commit dilutes two things at once: how quickly a reviewer can verify the preparation is correct, and how clearly the preparation's own justification holds up on its own terms.

Sometimes the honest discovery, partway through, is that the "small reshaping" wants to become something closer to a redesign. That discovery is information, not a mandate to keep going. The honest responses are to descope the preparation back down to what the current change actually needs, or to stop and surface the larger structural issue explicitly — as its own conversation, with its own justification — rather than quietly letting scope creep carry a preparation commit somewhere nobody signed up for.

Naming the failure mode helps recognize it in the moment: "preparatory" can become a label that launders an open-ended rewrite into what looks, from the outside, like a scoped feature branch. The label sounds disciplined even when the work underneath it has stopped being scoped at all. The honesty check is simply asking, at each step, whether the current edit is on the path to the unlock line or has wandered past it.

That question is easiest to answer honestly if it is asked before the branch grows long, not after. A preparation branch a day old is easy to compare against its original justification; a preparation branch left open for days on end can accumulate enough incidental improvements that reconstructing what was actually necessary for the unlock line takes real archaeology. Scope drift is cheaper to catch early, and a cheap way to catch it is to re-read the original thought experiment — the named X the code was supposed to become shaped like — and check the current diff against it.

A worked shape

Consider a variant hardcoded through several scattered conditionals — a pricing rule, say, checked inline in three different functions each time a new tier needs to be handled. The preparation commit concentrates that variation behind one seam: a single function or lookup that each of the three call sites defers to, still returning exactly the values it returned before.

javascript
// Preparation: concentrate the scattered variation behind one seam
// (behavior-preserving — every call site's output is unchanged)
function resolvePricingTier(customer) {
  if (customer.tier === 'enterprise') return ENTERPRISE_RATE;
  if (customer.tier === 'pro') return PRO_RATE;
  return STANDARD_RATE;
}

// Feature commit that follows: the new variant added in exactly one place
function resolvePricingTier(customer) {
  if (customer.tier === 'enterprise') return ENTERPRISE_RATE;
  if (customer.tier === 'pro') return PRO_RATE;
  if (customer.tier === 'nonprofit') return NONPROFIT_RATE; // new
  return STANDARD_RATE;
}

Read through the commit history, the arc is legible: the preparation commit is behavior-preserving, with existing tests passing unchanged, because it only relocated logic without altering any output. The feature commit that follows is small and intention-revealing — one new branch, in the one place variation now lives — and its new tests express exactly the new behavior being added.

What a reviewer sees at each step is proportionate to what actually changed. The preparation commit is verified by confirming behavior did not move — a fast check, because the diff is mechanical relocation. The feature commit is verified by reading the one new line and its accompanying tests — also fast, because the surrounding shape no longer buries it among the scattered places the old code would have required touching.

Project Inquiry