Technical debt is a concept that explains the added cost that quick or hacked-together code incurs in a project over a long period.
When you write code that is “easy” without ever going back to test, you are adding to the overall debt in which interest accumulates over time.
Now, technical debt can be addressed if properly tackled using refactoring - a process of optimizing, re-writing or organizing your code. In their book, ”Object-Oriented Software Engineering: A Use Case Driven Approach,” Ivar Jacobson, Magnus Christerson and Gunnar Övergaard, warn eventually your software may fall victim to software entropy, a principle that states a systems disorder can only ever be increased or maintained, never reduced.
Show Me an Example
As a contrived example, consider the following scenario...
- Liz Lemon creates an app like YouTube that allows users to upload videos, create channels and leave comments.
- As the launch day nears, Lemon finds several bugs that prevent videos from being uploaded under certain conditions.
- Since this is an app breaking error, it must be patched before the launch date.
- Lemon finds a way to patch it, but it’s not the most elegant solution. She decides to patch it now and then come back to it later to “clean it up.”
- After the app launches, more bugs, of the highest priority, are reported.
- Lemon spends the next few weeks patching bugs, completely forgetting about the patch she made prior to launch.
- Months later, suddenly most users can’t upload videos. It turns out that early patch inadvertently created another bug that remained dormant until certain conditions were met
- Now Lemon is having to revisit and repair that early patch with another patch
This example demonstrates that the app began to incur technical debt early on. The “interest” was never paid off, so it sat and accumulated until the “bank” hired a debt collector to come claim what was owed. Sometimes they will call you at home, sometimes at work, they’ll even call your family members or boss. Don’t let debt collectors be hired by your application.
There are many other ways technical debt can incurred. Some other factors include:
- Business pressure – It's like barometric pressure, except it’s not.
- No processes – There are no clear and defined processes to updating/adding code.
- Tightly-coupled components – Pieces of code that are tied to each other.
- No tests – Code that tests other code. Self-fulfilling prophecies.
- No documentation - “”
- Low adherence to standards – Twitter
OK, But What Can I Do?
What could Lemon have done differently in the scenario to prevent the debt? Take the list of factors and invert each of them.
- Reduce business pressure (usually not in your control)
- Create a process that you follow rigidly
- Modularize your code into smaller isolated chunks
- Install a test suite
- Document everything
- Create standards and hold everyone to them consistently
If you work in a team, most of these should already be in place. If they are and you are still incurring debt, you will want to take a step back and review each of them and find where you are failing.
Working in a very small team, or even alone, can present its own challenges such as lack of code reviews and quality assurance. In my experience, the only way you will achieve limited technical debt is being extremely proactive. You must be your own manager and set yourself to the highest standard you can.
The three biggest takeaways from this article should be to:
- Be proactive.
- Avoid the “I’ll go back and fix it later” by being honest with yourself. If you historically don’t go back and refactor, then do it right the first time.
- Create processes, and document everything for next time.
- If you use “TODO” comments (notes you make in your code to remind yourself to “come back and finish this later”), ensure part of your process is using an automated tool to find and flag any that are found in production code.