Lesson 9 of 17 · The Forces That Shape Code
Technical Debt and the Boy Scout Rule
"It's all technical debt"
You've heard this in any codebase with some history. Open a file, find something painful, and somebody on the team will say, "yeah, it's tech debt". The phrase carries no information at this point. It's a vague gesture at the general fact that code exists.
That's a problem. When everything is debt, nothing gets prioritized. The team can't argue for cleanup time because the catalog is infinite and undifferentiated. Leadership stops believing the word means anything because they've heard it used about so many different things. Engineers stop believing it too, and "we have tech debt" becomes a tired complaint instead of a fundable conversation.
The original definition
Ward Cunningham coined "technical debt" in 1992, and his metaphor was specific: shipping first-time code is borrowing, a little of it speeds you up as long as a rewrite repays it promptly, and the danger is never repaying.
Cunningham wasn't talking about bad code. He said so himself, years later: "I'm never in favor of writing code poorly but I am in favor of writing code to reflect your current understanding of a problem even if that understanding is partial." Debt, in his sense, is the gap between what the code encodes and what the team now understands. You repay it by refactoring as the understanding grows, and the sooner you do, the less interest you pay.
Today the term gets stuck on anything anyone disagrees with, and the word loses its meaning the same way "design pattern" did when it became a synonym for "any class with a name".
The borrowed-and-paid-back framing is the useful part. It tells you how to recognize debt and how to budget for repaying it.
What actually counts as debt
A short taxonomy of what teams call "tech debt", most of which isn't:
Bad code. Code that was wrong from the start. Buggy logic, broken contracts, mistakes nobody planned. That isn't debt, that's a defect. Treating it as debt lets the team avoid saying "this was wrong", which keeps them from learning from it.
Outdated code. Code that was right when it was written, and is wrong now because something outside it changed: a PHP version, a vendor API, a business rule. The team didn't borrow anything and didn't learn anything; the ground moved. That's the cost of survival, not debt.
Code you don't understand. Code that probably has its reasons, written by someone who isn't here anymore. Until you understand it, calling it debt is a guess, and the rewrite that "cleans it up" tends to reintroduce the bugs the original author was working around.
Code you disagree with. Someone made a different call than you would have. They might have been right. Calling it debt is just a way to say "I would have done it differently" with more authority than that opinion deserves.
Real debt. Code that encodes an understanding the team has since outgrown, and shortcuts taken under pressure, knowing they were shortcuts, with an explicit "we'll come back to this" attached. Those are the only things the term actually fits.
The taxonomy matters because each kind needs a different response. Defects need fixing. Outdated code needs migrating. Unfamiliar code needs reading. Disagreements need owners, not blanket "cleanup" budgets. Only real debt needs the borrowed-and-repaid frame.
The four kinds of real debt
Even within "real debt", not all debt is the same. Martin Fowler's quadrant, from 2009, is the cleanest way to slice it. He widened Cunningham's idea to include shortcuts taken on purpose:
Reckless and deliberate. We don't have time for design. Knew the right thing, didn't do it, didn't care. This is the kind that aged out of being defensible the day it was written.
Reckless and inadvertent. What's layering? Didn't know there was a right thing. Couldn't have known. It's the hardest kind to repay, because the team can't see it.
Prudent and deliberate. We must ship now and deal with the consequences. Knew the right thing, picked the shortcut on purpose, with a plan. The healthiest kind. The plan is what makes it healthy.
Prudent and inadvertent. Now we know how we should have done it. Did the best you could with what you knew about the problem, and learned more by building it. This is Cunningham's original case.
A team that can't tell the difference keeps arguing about "tech debt" the way people argue about the weather: a lot of words, no decisions.
The most useful question to ask about any piece of debt is: did we know better at the time? If yes, we owe the team a habit change. If no, we owe ourselves better feedback loops, so the same gap gets caught sooner next time.
Why debt compounds
The cost of change curve already showed why a small change in year one can be expensive in year three. The same shape applies to debt.
When you take a shortcut on day one, the shortcut isn't expensive yet. There's barely any code around it. Reworking it into its right shape would be a few minutes of work, if you ever did. By year three, the shortcut has callers. Other code grew around its assumptions. The thing that was supposed to be temporary is structural.
This is the part of debt the original metaphor captures and the casual usage misses. Real debt accrues interest. The longer you leave it, the more code is built on top of it, and the more expensive the repayment becomes. A two-day shortcut today is rarely a two-day repayment in year three.
The framing change is small but useful. "We have debt" is a status. "This debt costs us a day on every change that touches billing" is a budget. The second one funds work; the first one doesn't.
The Boy Scout Rule
The other half of this lesson is the Boy Scout Rule. Robert Martin's version in Clean Code is to leave the campground cleaner than you found it. Applied to code: every time you touch a file, leave one or two small improvements behind. A better name. A clearer condition. A removed dead branch. Compounded across every change, this beats any "cleanup sprint" the team will never schedule.
How the Boy Scout Rule goes wrong
Scope creep. A one-line bug fix becomes a 600-line refactor. The PR is unreviewable. The fix is hidden inside a pile of cleanup. Reviewers can't tell what's the bug fix and what's the rewrite. Now the change is risky for reasons that have nothing to do with the bug. It also sits unreviewed, because nobody wants to approve it without reading every line.
Drive-by reformatting. Renames, restructures, and stylistic changes that look like cleanup but are really preference changes. Worse: they reset blame across hundreds of lines, so the next person trying to understand why a piece of code exists gets a useless
git blamepointing at someone who only changed the formatting.Cleanup as an excuse. "Boy scout" gets used as cover for refactors that should have been a planned project. The cleanup is bigger than the rule was meant for, doesn't fit in one PR, and gets done halfway. A half-done refactor looks like a pattern the team chose on purpose, not an interruption, so the next person copies it instead of finishing it.
If your "small cleanup" needs more than ten minutes of detour from the work you came to do, it isn't a Boy Scout improvement anymore. It's a project, and it should be scoped, planned, and reviewed like one.
What the rule should actually look like
The good version is small and disciplined:
Minutes, not hours. Never the kind of change that needs its own design discussion.
Tightly scoped to the file or function you were already in. You came for a reason. The cleanup is in service of that reason.
Aimed at readability, not architecture. Names, dead code, redundant comments, slightly clearer control flow. Things that make the next reader's life cheaper without changing what the code does.
Honestly separable from the main change. If a reviewer asks "could you do this in a separate commit?", the answer should always be yes.
Two things stay off the list even when they fit the budget. Code with no test coverage, because you can't verify the behavior didn't change; add tests first, then clean up if you still want to. And code that other teams or services depend on, because the boundary you're "tidying" might be a contract.
You'll often see something you'd like to fix and leave it alone, because it's bigger than the rule allows. Walking past it is part of the practice. None of this defends "if it ain't broke, don't touch it": dead code is broken in a way that's easy to miss, and code that only one person understands gets worse over time. Some of the most important cleanups in any codebase are the ones nobody asked for.
The strategic frame
The Boy Scout Rule is the daily habit that keeps a codebase from getting worse. It's a real thing, it works, and the codebases that follow it are noticeably better to live in. Repaying actual debt is a different job. It's a project, with the same discipline as a feature: a problem statement, a scope, a plan, tests, reviewers, a definition of done.
The two work together. The daily habit holds the line. The planned projects move it. A team that does only the first stops getting worse but doesn't get better. A team that does only the second sees big improvements and then watches them rot, because the daily habit isn't there to defend them. A team that does both has a chance.
When you hear "we'll fix it with the Boy Scout Rule", treat it the same way you'd treat "we'll save money by skipping coffee". It's true at small scales and a delusion at the size of the actual problem.
A practical pattern: the cleanup PR
When you find something bigger than a ten-minute detour, the right move is to make it a separate, small, focused PR with no business logic change in it.
What that buys you:
The reviewer can review it as a refactor and verify nothing changed behaviorally.
The feature PR stays small and easy to reason about.
If the refactor turns out to be wrong or breaks something, it can be reverted without taking the feature with it.
The git history is honest. One PR is "fix invoice rounding". The other is "rename
Invoice::amounttoInvoice::amountInCents". A future archaeologist can tell them apart.
The pattern feels slow, and it's still the cheapest way to land cleanups without dragging unrelated work behind them.
The one thing to remember
Technical debt is something you took on or grew out of; bad code is something you wrote; outdated code is something the world did to you. They look the same in a file, and they need different responses. Get the names right and the conversations get easier. Keep using "tech debt" for everything and the conversations get nowhere.
The Boy Scout Rule is the small habit. Real repayment is a project. Don't ask either of them to do the other one's job.
Related Links
- Ward Explains Debt MetaphorWard Cunningham on what he meant when he coined "technical debt", with the video and transcript.
- Technical Debt QuadrantMartin Fowler's 2009 quadrant: deliberate or inadvertent, prudent or reckless.
- The Boy Scout RuleRobert C. Martin's original essay from 97 Things Every Programmer Should Know.
- Technical Debt is over-usedLarry Garfield on why most of what gets called technical debt is something else.