Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Continuous refactoring works when small, behavior-preserving improvements happen during ordinary feature and bug-fix work, not in a separate cleanup project. Three norms make that safe: clean up the code you are already changing, keep structural changes distinguishable from functional ones, and let fast tests and review decide whether a change is safe to merge. A team that follows these norms does not need a cleanup calendar, though larger planned efforts still have a place.

Start with the definition that makes the culture workable

Refactoring means improving the internal structure of code while preserving its external behavior. That definition is the foundation of the whole practice. If a change alters what the software does, it is a behavior change, even if it also tidies things up. The team’s job is to keep the two kinds of change visible: in how work is scoped, in how it is described, and in how it is reviewed.

Five practices that make refactoring routine

1. Clean up the code you are already touching

Martin Fowler’s article “Opportunistic Refactoring,” dated 1 November 2011, argues that refactoring should be built into the wider development process rather than held back for a dedicated phase. When you meet unclear code, improve it then or shortly afterward. Fowler also allows that scheduled refactoring work has a place, so the culture does not have to choose one approach exclusively. The practical rule is simple: if you have to read code to change it, leave it a little easier to read than you found it.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Split the cleanup out when it makes the change hard to judge

Gerrit Code Review’s project documentation, “Crafting Changes,” calls this habit the “boy scout rule” and attributes the term to Martin Fowler. It also advises that a change should do one thing. When useful cleanup would bury a functional change in a large diff, the documentation suggests making the cleanup a preparatory change, submitted separately. Reviewers can then confirm that the structural change alone leaves behavior intact, and the functional change becomes much easier to judge.

Gerrit’s guidance also gives reviewers a question to ask: does this cleanup fit the scope of the change under review? Cleanup that is related to the code being changed usually belongs in the same review. Cleanup in unrelated modules usually belongs in its own change.

3. Refactor only when the tests are green

Fowler’s condition is direct: “This continuous attention to the code is important – but do remember that you should only refactor when your tests are green.” The test suite is what lets a refactoring claim to preserve behavior. The limit is that tests only check what they cover. A passing suite is strong evidence that the behavior they exercise is unchanged. It is not proof that no regression exists elsewhere, so refactorings in poorly tested areas need extra care, such as adding characterization tests first or keeping the step smaller.

4. Make feedback available to the whole team

DORA’s published capability guidance for continuous delivery asks whether fast quality and deployability feedback is available to everyone on the team, not only to the person who wrote the change. That question matters for refactoring because cleanup is often done by developers who did not originally write the code. If a slow build or a flaky test suite is the only way to learn whether a change is safe, people will avoid cleanup. Fast, shared feedback makes small improvements cheap enough to attempt.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

5. Treat review as an iterative process

Google Cloud’s documentation, “Google Cloud’s approach to change,” describes CI/CD and human review as part of its change process and presents review as iterative, with changes often revised before they land. Its stated coding standards emphasize correctness, clarity, concision, and efficiency. In practice, a refactoring is a good candidate for review because it changes shape without changing outcomes, and reviewers can focus on whether the new structure is clearer. The official statement on the process reads: “Our code development process increases the quality and reliability of our code.”

A hypothetical example of the habit in action

Suppose a team needs to add a loyalty discount to a checkout function that calculates tax, shipping, and totals in one long block. A team that refactors continuously might work in two steps, with no claim about any real project behind this illustration:

  1. Change 1 (preparatory, behavior-preserving): Extract the tax calculation into its own function and cover it with existing tests. The commit message states that no behavior changes. Reviewers check that the outputs match before and after.
  2. Change 2 (functional): Add the loyalty discount to the now-smaller total calculation, with tests for the new rule. Reviewers judge only the new behavior.

If the tax extraction had been folded into the discount change, reviewers would have had to separate the two kinds of edit in their heads. The split costs one extra review, but each review is simpler.

Comparing opportunistic cleanup with a scheduled effort

Most teams end up using both approaches. The table compares them along the axes that matter most for delivery and risk.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Consideration Opportunistic cleanup during ordinary work Scheduled, larger refactoring effort
Scope Limited to code already being changed or read Can span modules or a whole subsystem
Separation from functional change Usually a preparatory change in the same stream of work, kept separate when it aids review Typically its own body of work, so separation is easier to plan
Review impact Small, focused diffs when the cleanup is kept narrow Larger reviews unless split into steps
Feedback and risk Each step is small enough that a failure is quick to locate, provided tests and deployment feedback are fast Risk accumulates across many changes; the sources do not establish a specific failure rate for either approach
Best fit Local clarity problems that slow current work Structural problems that block several planned features

When a planned effort is still the right call

  • The structural problem spans many modules, so no single feature change can reasonably carry the work.
  • The change needs coordination across teams or services that cannot be made incrementally.
  • The affected area has weak test coverage, so the team needs to build safety nets before any structural change.

Fowler’s guidance does not exclude these cases. The choice is about scope and risk, not a fixed cadence.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Enabling conditions from continuous delivery

DORA defines continuous delivery as “the ability to release changes of all kinds on demand quickly, safely, and sustainably.” Its diagnostic questions give a useful checklist for whether a team can refactor frequently:

  • Does the software stay deployable throughout its lifecycle?
  • Is deployability prioritized when work is planned and reviewed?
  • Do all team members have fast feedback on quality and deployability?

If the answer to any of these is no, refactoring will be the first activity to be deferred under delivery pressure. Fixing the delivery pipeline is often the prerequisite for a refactoring culture, not an alternative to it.

What the evidence does and does not support

The primary guidance on this topic is practical rather than quantitative. It supports the following claims:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Refactoring can be integrated into ordinary development, with tests as the condition for making structural changes.
  • Separating cleanup from functional changes can make reviews easier to judge.
  • DORA reports associations between continuous delivery practices and delivery performance, availability, quality, burnout, job satisfaction, and organizational culture. These are associations with a set of practices, not isolated proof that refactoring causes any of them.

The available sources do not establish an ideal percentage of engineering time for refactoring, and they do not measure refactoring’s independent effect on delivery speed. Any team that promises a fixed cleanup quota or a specific speed gain from refactoring alone is going beyond the evidence. Martin Fowler’s book Refactoring: Improving the Design of Existing Code is a detailed technique reference for teams who want more depth on specific transformations and on tests.

Starting the habit in your team

  1. Agree on the definition. Write down that a refactoring preserves behavior, and that a change which alters behavior is labeled as such in its description.
  2. Check the test and feedback loop first. If a typical test run is too slow for developers to run before committing, shorten that loop before asking for more cleanup.
  3. Allow small cleanup inside feature work. Ask developers to improve code they have to read to make a change, and to keep the cleanup narrow.
  4. Split when the diff becomes hard to judge. Move cleanup into a preparatory change whenever reviewers would have to separate two kinds of edit mentally.
  5. Review structure explicitly. Ask reviewers to confirm that a refactoring change leaves behavior unchanged and that it stays within the scope of the review.
  6. Plan the large items separately. Track structural problems that exceed a single change, and schedule them when they block planned work.

If cleanup starts slowing delivery

  • Changes keep growing. Enforce the one-thing-per-change rule and move unrelated cleanup into its own change.
  • Developers avoid touching code. Check whether tests and deployment feedback are slow or flaky, since that is a delivery problem before it is a refactoring problem.
  • Reviews stall. Ask whether the preparatory changes are described clearly enough to be checked on their own.

Refactoring is not free, but made small and kept honest about behavior, it becomes an ordinary part of changing software rather than a project that waits for permission.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.