Technical Debt
Technical debt (also known as design debt or code debt) is a concept in software development that reflects the implied cost of additional rework caused by choosing an easy (limited) solution now instead of using a better approach that would take longer.
1. The Metaphor
Coined by Ward Cunningham, the metaphor compares coding to financial debt:
- Principal: The quick-and-dirty code you write to ship faster.
- Interest: The extra time you have to spend in the future working with that messy code. The longer you leave it, the more "interest" you pay in the form of slower development speed.
Eventually, if you don't pay down the principal (refactor), the interest becomes so high that you spend 100% of your time fixing bugs and fighting the code, with zero time for new features (Bankruptcy).
2. Causes
- Business Pressure: "We need this feature by Friday, no matter what."
- Lack of Documentation: New developers don't understand the design and write code that doesn't fit.
- Lack of Tests: Fear of breaking things prevents developers from cleaning up code.
- Incompetence: Developers simply don't know how to write clean code.
3. The Technical Debt Quadrant
Martin Fowler distinguishes debt into four categories based on intent and context:
| Reckless | Prudent | |
|---|---|---|
| Deliberate | "We don't have time for design." (Calculated risk) | "We must ship now and deal with consequences." (Strategic) |
| Inadvertent | "What's layering?" (Ignorance) | "Now we know how we should have done it." (Learning) |
4. Managing Technical Debt
You cannot avoid debt entirely, but you must manage it.
- Acknowledge It: Track debt in your backlog just like features.
- The Boy Scout Rule: "Always leave the code behind in a better state than you found it."
- Dedicated Refactoring Time: Allocate a percentage of every sprint (e.g., 20%) to paying down debt.
- Definition of Done: Ensure your "Done" criteria includes writing tests and documentation.
programming/agile-methodology programming/code-review-best-practices programming/software-testing-basics