Dealing with technical debt
Join the DZone community and get the full member experience.Join For Free
we’re drowning in technical debt. we have a mountain to climb and don’t really know where to start. sound familiar? for many of us working on legacy code bases this is the day-to-day reality. but what to do about it?
how did we get here?
technical debt is always the fault of those “other guys”. those idiot developers that were here a few years ago. morons. obviously couldn’t code their way out of a game of life if their on-going existence depended on it.
i hate to tell you but: we are those other guys . the decisions we make today will look foolish tomorrow. we’ll have more information then, a different perspective; we’ll know how the product and technology were going to evolve. we can’t know that today, so many of our decisions will turn out to be wrong.
where to start
classes are like best-selling novels – some are spectacularly more popular / more debt-laden than others. one class, one package, one module – will be much worse than the others. there’ll be a handful of classes, packages etc… that are much worse than all the rest.
how does this happen? well, one class ends up with a bit of technical debt. next time i come to change that class, i’m too lazy to fix the debt, so i just hack something together to get the new feature done. then next time round, there’s a pile of debt – only that guy’s too busy to fix it so he adds in a couple of kludges and leaves it. before you know it, this one class has become a ten thousand line monster that’s pure technical debt.
it’s like the broken-windows theory – if code is already crappy, its much easier to just make it a little more crappy. if the code’s clean, it’s a big step to add in a hack. so little by little, technical debt accumulates in areas that were already full of debt. i suspect technical debt in code follows a power law – most classes have a little bit of debt, but a few are really shitty, with one diabolical class in particular:
where to start? resist the temptation to make easy changes to relatively clean classes – start with the worst offender. it will be the hardest to fix, it might take a long time – but you’ll get the best bang-for-buck by fixing the most debt-heavy piece of crap code. if you can fix the worst offender, your debt will have to find somewhere else to hide.
the 80/20 rule
there’s a cliché that 80% of the cost of software is maintenance, only 20% is the initial build.
let’s imagine a team that has 1200 hours a month to spend on useful work. for that 1200 hours of useful work, we’ll spend four times that much over the lifetime of the software maintaining it – from the 80/20 rule. although we completed 1200 hours of feature work this month, we committed ourselves to 4800 hours of maintenance over the lifetime of the code.
that means next month, we have to spend a little of the 4800 hours of maintenance, with the rest of the time spent on useful, feature-adding work. however, adding new features commits us to even more maintenance work. the following month, we’ve got nearly twice the code to maintain so spend nearly twice the amount of time maintaining it and even less time producing value-adding features. month-by-month we spend more and more time dealing with the crap that was there before and less and less time adding new features.
does this sound familiar? this is what technical debt feels like. after a couple of years the pace has dropped; you’re spending half your time refactoring and fixing the junk that was there before. “if only we could get rid of this technical debt”, you cry.
what is technical debt?
we can all point to examples of crappy, debt-laden code we’ve seen. but what’s the impact of technical debt? technical debt is simply an inability to quickly make changes to an existing system. this is the cost to the business of technical debt – what should be quick changes take an unpredictably long time.
what do we do when we remove technical debt? we generalise and find more abstract solutions. we clarify and simplify . we remove duplication and unnecessary complexity .
the net effect of reducing technical debt, is to reduce inventory .
perhaps the amount of code – our inventory - is a good approximation for the amount of technical debt in a system. if i’m confronted with a million lines of code and need to make a change, it will probably take a while. however, if i’m only confronted by 1000 lines of code the change will be much quicker. but, if i’m confronted by zero lines of code, then there’s zero cost – i can do whatever i like. the cost of making a change to a system is roughly proportional to the size of the system. large, complex systems take longer to make changes to than small, self-contained ones.
all code is a liability – the more code you have, the bigger the debt. when we’re paying back technical debt – are we really just reducing inventory? is what feels like technical debt actually interest payments on all the inventory we hold?
what are the options?
one option is to down-tools and fix the debt. not necessarily throw everything out and rewrite, but spend some time cleaning up the mess. the big bang approach to dealing with technical debt. it’s pretty unusual for the business to agree to a plan like this – no new features for a year? really? with no new features for a year what would all those product managers do all day?
from the 80/20 rule, the lifetime cost for any piece of code is four times what it cost to create. if it took three months to make, it will take a year to pay back. so wait, we’re gonna down tools for a year and only pay back three months of technical debt? seriously? we’ll be marginally better off – but we’ll still be in a debt-laden-hell-hole and we’ll have lost a year’s worth of features. no way!
even if you try to do big bang, it ends up becoming the dedicated team approach. as a compromise, you get a specific team together to fix the debt, meanwhile everyone else carries on churning out new features. one team are removing debt; while another team are re-adding it. what are the chances that debt is being removed faster than it’s being added? exactly. nil.
it makes sense – you need a team removing debt four times bigger than the team adding new features just to stay still .
you could adopt a policy of trying to remove technical debt little and often – the boy scout approach. on every single development task try and remove debt near where you’re working. if there are no tests, add some. if the tests are poor, improve them. if the code’s badly factored, refactor it. the boy scout rule – leave the camp cleaner than you found it.
this is generally much easier to sell, there’s only minimal impact on productivity: it’s much cheaper to make changes to a part of the system you understand and are already working in than to open up whole new ones. but over time you can massively slow down the rate at which debt grows. inevitably the system will still grow, inevitably the amount of debt will increase. but if you can minimise the maintenance cost you’ll keep the code small and nimble for as long as possible.
if we can lessen the maintenance cost of code even just a little we can save ourselves a fortune over the life of the code. if we can reduce the multiple to just three times the initial cost, so our 1200 hours work only costs 3600 hours in maintenance, we’ve saved enough development capacity to build another feature of the same size! for free! hey, product manager, if we do our job better it’ll take no longer and you’ll get free features. who doesn’t want free features?
if we can create well-crafted , dry , solid code with good test coverage we have a good chance of minimising the lifetime maintenance cost. this is the best way we can keep our productivity up, to try and avoid getting mired in technical debt and keep the code base responsive to changing requirements. it’s the only way we can remain productive and agile.
frankly, anything else is just unprofessional . if you’re deliberately committing your company to spend excessive amounts maintaining your shitty code – what the fuck, exactly, are they paying you for?
Opinions expressed by DZone contributors are their own.
Microservices With Apache Camel and Quarkus (Part 2)
Health Check Response Format for HTTP APIs
What ChatGPT Needs Is Context
Comparing Cloud Hosting vs. Self Hosting