Software Engineering ยท Code Quality
Restructuring existing code to improve its internal design and readability while deliberately keeping its external behavior unchanged.
Mental model: Like reorganizing a closet โ same clothes, easier to find them.
Example: Extracting a 200-line function into five smaller named functions without changing what the code outputs.
In practice: Because behavior must stay unchanged, refactoring is safest when backed by a solid test suite โ without one, you can't be confident you haven't broken anything.