Software Development

What is Refactoring?

Quick answer

Restructuring existing code to make it cleaner, simpler, or easier to maintain without changing what the software does.

Refactoring, explained

Refactoring improves the internal design of code while keeping its external behaviour the same. Common refactorings include renaming unclear variables, splitting long functions, removing duplicate logic, and reorganizing files. The term was popularized by Martin Fowler's 1999 book on the subject.

For example, if an invoicing app calculates tax in five different places, a developer might refactor the logic into one shared function, so a future tax rule change needs editing only once. Refactoring is one of the main ways teams pay down technical debt. It is safest with a good set of automated tests, which confirm that behaviour has not changed. Large refactors are usually done in small steps alongside regular feature work rather than as a risky rewrite.

Related terms

Guides that mention Refactoring