Unit content
Refactoring and technical debt
Refactoring changes the internal structure of software while preserving the external behavior that matters.
Examples include extracting a function, moving a responsibility to a more appropriate module, replacing duplicated logic with one implementation or introducing a clearer interface.
A safe refactor separates two questions:
- does behavior need to change?
- does the current structure make future changes harder than necessary?
When possible, preserve behavior first and verify it with tests or other checks before adding new behavior. Mixing a large structural rewrite with a feature change makes failures harder to localize and review.
Technical debt is a design or implementation compromise that makes future change more expensive. Debt can be intentional—for example shipping a simple implementation before scale requires a more complex one—but it carries a continuing cost until repaid or deliberately accepted.
Not every imperfect abstraction needs cleanup. Refactoring is valuable when it reduces concrete change cost, duplication, coupling or defect risk rather than merely making code look different.