Refactoring

Refactoring is the practice of improving the design of existing code through small, behavior-preserving changes. As Martin Fowler describes it, the technique improves the design of an existing code base in a controlled way, applying a series of transformations that each leave the program’s observable behavior unchanged while making the structure clearer.

The key discipline is that refactoring is done in small steps. Because each individual change preserves behavior, the chance of introducing a serious error is reduced, and the programmer can stop at any point with working code. This is what distinguishes refactoring from a general rewrite or redesign.

Refactoring depends on tests. A reliable suite of automated tests lets a developer make a structural change and immediately confirm that behavior has not changed, which is why refactoring is closely tied to practices such as unit testing and test-driven development. Without that safety net, restructuring code becomes risky.

Fowler frames refactoring as a response to code smells: surface signs that a deeper design problem exists. When code becomes hard to understand or modify, named refactorings provide a vocabulary of small, repeatable moves to clean it up. Fowler considers his work on refactoring his most influential contribution to software development.

Sources

Last verified June 8, 2026