refactoring
noun
Refactoring changes the internal structure of existing code without changing observable software behaviour. The aim is to make code easier to understand and modify.
The developer did some refactoring first so the new payment method would be easier to add.
Refactoring changes the structure of existing code while keeping the software's behaviour the same for users. Examples include splitting a long function, clarifying names or combining duplicated code. These changes often make future maintenance and expansion easier.
How does refactoring work?
Refactoring usually consists of small, focused steps. After each step, the developer checks that existing behaviour is preserved. Automated tests help by quickly revealing unexpected changes. A Glossary · In briefcode reviewA code review is an assessment of a code change by another developer. They check its behaviour, readability, and maintainability, among other things, before the change is merged.Read more can also expose unclear decisions or missed risks.
Refactoring often happens during regular development. A developer may improve an awkward piece of code before adding a feature. It can also be a separate task when parts of a Glossary · In briefcodebaseA codebase is the collection of source code used to build and maintain a software product or component.Read more are difficult to understand or change.
Refactoring, rewriting and optimization
A rewrite rebuilds a component and may replace a larger amount of existing code. Refactoring generally proceeds in smaller steps within the current code. This makes changes easier to check, although even a small adjustment can introduce a bug.
Optimization has a different goal: making software faster or reducing memory usage. Refactoring concerns internal structure while preserving observable behaviour. A better structure can, however, make later optimization easier.