What is Refactoring?
Refactoring improves code's internal structure without changing its external behavior — renaming for clarity, splitting bloated functions, removing duplication. Done continuously in small steps (protected by tests), it pays down technical debt before the interest compounds.
The discipline is the "without changing behavior" clause: refactoring is not adding features, not fixing bugs, and not a three-month rewrite wearing a respectable name.
Worked example
Touching the invoicing module for a small feature, a developer first spends forty minutes refactoring: the 300-line calculate() becomes four named functions, tests still green, behavior identical. The feature then takes an hour instead of a day — and the next person to open that file inherits clarity instead of archaeology. Boy-scout rule: leave it cleaner than you found it.