Refactoring and technical debt are important concepts, especially so in agile software development. What are they?
Refactoring is modifying the internal structure of code without changing its behaviour. All functional tests should pass with the same results after the code has been refactored. If it behaves the same, why do we need to do it?
Refactoring is important to maintain the long-term quality of the code and platform of which the code is a part. If the developers don’t do some refactoring on a regular basis, “technical debt” will creep into the system.
It will continue growing to the point where new development becomes difficult if not impossible. In my experience, the overall technical debt of a system increases exponentially (not linearly) as the technical debt of individual parts increases. That is because the technical debt of a given part increases as the overall complexity and entropy of the system increases.
I believe there are actually two types of technical debt: micro and macro. Most technical debt is micro: that belonging to a single component. Macro tech debt is related to the overall architecture of a system. That is, how the components interact with each other.
You should be repaying micro tech debt continuously you are building stories. Refactoring is a development practice that should be part of the standard process that developers follow as they deliver stories. If you are following Test-Driven Development practices, this is explicitly clear: the process goes Red, Green, Refactor. Red: write a test that fails. Green: write some code that makes the test pass. Refactor: improve your code.
Macro technical debt is more complex and generally requires embarking on an explicit project, with its own features, stories, product owner, etc. Getting buy-in from stakeholders can be difficult for these projects, and will require careful thinking and communication around the benefits. Some examples of macro technical debt could be:
When refactoring, make sure you are doing it for a specific reason! Do not refactor if you can’t think of a benefit. Some examples include: