openskills.info
Course Preview

Refactoring

Refactoring is a disciplined technique for restructuring existing code, altering its internal structure without changing its external behavior. You apply a series of small behavior-preserving transformations and run the tests after each one, keeping the code fully working while its design improves.

itSoftware engineering

Refactoring

Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior-preserving transformations. Each transformation, called a refactoring, does little by itself, but a sequence of them can produce a significant restructuring. Because each step is small, it is less likely to go wrong. The system stays fully working after every step, which reduces the chance of a serious break during the restructuring.

Fowler's book defines the term twice. As a noun, a refactoring is a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior. As a verb, to refactor is to restructure software by applying a series of refactorings without changing its observable behavior. The word is not a synonym for cleaning up code; restructuring is the general term, and refactoring is one specific technique inside it.

Behavior preservation

External behavior is what a caller observes: return values, side effects, error behavior, and performance that matters. Refactoring does not alter those. It changes how the code is organized, named, and decomposed.

Behavior preservation is the boundary that separates refactoring from other changes. When you add a feature, you change behavior. When you fix a bug, you change behavior. When you refactor, you keep behavior constant and improve structure. Mixing the two makes regressions hard to attribute, because a failure can no longer be traced to one kind of change.

The practical tool for checking preservation is a test suite. Refactoring without tests is guesswork about whether behavior survived. Fowler describes automated tools as valuable but not essential; small steps and frequent testing are what keep the technique safe.

Code smells

A code smell is an indicator of a problem that refactoring can address. Smells are easy to spot and easy to fix, but they may be symptoms of a deeper problem in the code. The smell is the signal; the refactoring is the response.

Continue the course

This section is part of the paid course.

See pricing to subscribe, or log in if you already have access.

Where this skill leads

Relevant careers

See how this topic contributes to broader role-level skill maps.

Sources