4.5.20 · D4Software Engineering

Exercises — Technical debt — types, managing

3,299 words15 min readBack to topic

This page is a self-test ladder. Work each problem before opening its solution. Levels climb from "can you recall the words" (L1) to "can you invent and defend a policy" (L5). Every symbol used here is built in the parent note — if a symbol feels unfamiliar, re-read it there first.


Level 1 — Recognition

L1.1 — Which of these is technical debt, and which is a bug? (a) A function returns the wrong tax total. (b) A function returns the correct total but is 400 lines with no tests and copy-pasted three times.

Recall Solution L1.1

(a) = bug — the behaviour is wrong. (b) = technical debt — the behaviour is correct, but the code is costly to change/understand/extend. Debt is about changeability, not correctness. This is the single most tested distinction in the topic.

L1.2 — Name the two financial parts of technical debt and match each to its plain meaning: (i) cost to fix the shortcut once, (ii) recurring extra effort each future change.

Recall Solution L1.2

(i) = Principal (). (ii) = Interest (rate applied over changes ⇒ total ). Money-metaphor mnemonic: you borrow (shortcut), you pay interest until you repay the principal.

L1.3 — Fowler's quadrant has two axes. Name them.

Recall Solution L1.3

Axis 1: Deliberate vs Inadvertent (did you choose the debt?). Axis 2: Reckless vs Prudent (did you plan/track it?). The only "healthy" cell is Deliberate + Prudent.


Level 2 — Application

L2.1 — A logging module: days, rate , expected changes , fix cost days. Should you refactor now?

Recall Solution L2.1
  • Total interest days. Why: that's the whole extra time the mess will steal across all 8 changes.
  • Compare: vs . Since , the rule fails.
  • Decision: do NOT refactor. The one-time fix (12) costs more than the total interest you'd ever avoid (9.6). Net loss from refactoring days.

L2.2 — Same module, but you re-estimate: it's high-traffic, so (not 8). Recompute and decide.

Recall Solution L2.2
  • Total interest days.
  • ⇒ rule holdsrefactor now. Net saving days.
  • Lesson: the only number that changed was . High-traffic code almost always earns its refactor because total interest scales linearly with how often you touch it.

L2.3 — Classify: A team knows about a hacky auth workaround, files a ticket, and schedules the fix next sprint. Which quadrant?

Recall Solution L2.3

Deliberate (chosen on purpose) + Prudent (tracked, with a plan) = Deliberate–Prudent = the healthy cell. The ticket is exactly what upgrades it from reckless to prudent.


Level 3 — Analysis

L3.1 — The break-even point. For , rate , : how many future changes make refactoring exactly break even? Above what should you refactor?

Recall Solution L3.1

Break-even is where fixing and keeping tie: . Why rearrange? We want the answer as a number of changes, so we isolate — divide both sides by (allowed because ), which cancels on the right and leaves alone: The picture below shows the two costs as straight lines meeting at — look at it first, then read the decision.

Figure — Technical debt — types, managing

Reading the figure: the red sloped line is total interest — it starts at the origin and climbs by day per change. The black horizontal line is the principal — flat, because you pay it once. They cross at the black dot . Left of the dot the red line sits below (keep the debt); right of the dot it rises above (repay). Axes: horizontal = (number of future changes), vertical = cost in days. Decision: for refactor; for leave it; at exactly (the tie) ⇒ keep the debt (net saving is zero, so the tie breaks toward not spending the principal).

L3.2 — Reading the two lines. In the figure above, one line is flat and one slopes up. Which cost is which, and why does the shape make sense?

Recall Solution L3.2
  • Flat line = principal . You pay it once, so it does not depend on ⇒ horizontal. (Black in the figure.)
  • Sloped line = total interest . It grows by for every extra change ⇒ a straight line through the origin with slope . (Red accent in the figure — the key object.)
  • They cross at . Left of the crossing the sloped (interest) line is below → carrying debt is cheaper → keep it. Right of the crossing interest overtakes → repay. On the crossing they are equal → keep (tie rule).

L3.3 — Debt ratio. A codebase has remediation cost 40 developer-days and total development cost 200 developer-days. Compute the debt ratio and say in one sentence what it means.

Recall Solution L3.3

Meaning: it would take an extra 20% of the effort already invested just to clean the existing shortcuts — a tracking number to watch over time (rising ratio = accumulating debt).


Level 4 — Synthesis

L4.1 — Two competing repairs, one budget. You have 10 days this sprint. Two debt items:

  • Item A: , rate , , .
  • Item B: , rate , , .

You can only fund one. Which gives more net saving, and by how much?

Recall Solution L4.1

Use the net saving quantity: (total interest avoided minus the one-time fix). Fund only where it is positive.

  • A: total interest ; net saving days.
  • B: total interest ; net saving day.
  • B loses money (net negative) — do not fund it. Fund A, saving 6 days. A beats B by days of net value.
  • Insight: high (traffic) on Item A dominates. Prioritise the high-traffic debt, matching the parent's rule "fix debt in code you change often first."

L4.2 — Reserving sprint capacity actually drives repayment. Your team ships 20 story-points/sprint but velocity is dropping. You adopt a "reserve 20% for refactoring" rule. How many points/sprint go to debt paydown, and — visually — how does reserving those points make repayment happen, where "pay later" fails?

Recall Solution L4.2
  • Reserved points points/sprint for debt.
  • Concrete example over 3 sprints. Say the debt backlog is 12 points. With the reserve, each sprint spends 4 on debt: sprint 1 → 8 left, sprint 2 → 4 left, sprint 3 → 0 left — cleared in 3 sprints, guaranteed, because the 4 points are booked before features compete for them. Under "pay later," features expand to fill all 20 points every sprint (they always feel urgent), so 0 debt points get spent and the backlog grows.
  • The figure makes the two policies visible side by side:
Figure — Technical debt — types, managing

Reading the figure: each bar is one sprint's 20 points. The red slice is the 4 reserved debt points; the black slice is feature work. Under "reserve 20%" (left group) the red slice appears every sprint and the debt-remaining line (annotated) marches 12 → 8 → 4 → 0. Under "pay later" (right group) the red slice is absent — every bar is all-black feature work — and debt never falls. The visual lesson: a booked slot gets used; an unbooked intention does not.

  • Advantage stated plainly: reserving makes repayment scheduled, so it happens; "later" never arrives because features always feel more urgent (the debt-spiral). See Agile Sprint Planning for where this reservation lives, and Refactoring for how the 4 points get spent.

Level 5 — Mastery

L5.1 — Derive & defend the "optimal debt" claim. The parent says "you can never have zero debt; some is optimal." Using the model, show why driving debt to zero can lose money, and state the exact condition under which a debt item should be left unpaid.

Recall Solution L5.1
  • Fixing an item costs and saves at most of total interest.
  • Net saving of fixing . This is negative whenever , and zero at the tie .
  • So for any item with — typically cold code where is small (recall the edge case: total interest is exactly , so fixing always loses) — spending destroys value. "Zero debt" forces you to fix those too, so it loses money.
  • Exact condition to KEEP debt: (equivalently ). Note the "" includes the tie — at exact equality you keep, matching the boundary rule. This defines prudent debt: consciously left because the fix isn't worth it. Optimal debt level = fix everything with , keep the rest.
  • Links: keeping/leaving is a call about Software Maintainability; the "keep it clean where it's hot" spirit is the Boy Scout Rule fed by Continuous Integration and Unit Testing (tests make repayment safe).

L5.2 — Break-even under a changing rate. A module currently has rate , , . A dependency upgrade would double the rate to (each change now costs twice as long). How does the break-even change, and what does that tell you about ignored Code Smells?

Recall Solution L5.2
  • Before: changes.
  • After (): changes.
  • The break-even dropped from 6 to 3 (halved, since and doubled). As the rate rises, far fewer future changes are needed to justify a fix — worsening code smells make refactoring more urgent, not less. Rising shrinks the "keep it" zone. This is the quantitative face of the "debt spiral."

L5.3 — Full policy synthesis. Given a backlog of 3 items, produce a fund-in-order list under an 11-day budget:

  • X:
  • Y:
  • Z:
Recall Solution L5.3

Compute net saving for each:

  • X: .
  • Y: .
  • Z: reject (loses money).
  • Rank by net saving: Y (4.6) > X (4) > Z (reject).
  • Budget check: fund Y (5 days) then X (6 days) = 11 days, exactly the budget. Total net saving days. Z is left as prudent debt.
  • This is the whole management loop in one problem: Visible (listed) → Quantify (net saving) → Prioritise (ranked) → Pay-down (fund Y, X) → Prevent (leave Z tracked). See Coupling and Cohesion and Test Driven Development for reducing the rate at the source so future backlogs shrink.


Flashcards

Recall What is the break-even number of changes for a debt item?

— refactor when , keep the debt when (the tie keeps).

Recall How do you rank competing debt items?

By net saving (highest first), rejecting any with negative net; then fill the budget.

Recall Difference between the interest rate

and total interest? is a per-change fraction (slowdown per change); total interest is the lump sum of days across all changes.

Recall If the interest rate

doubles, what happens to break-even ? It halves (), so refactoring becomes justified after fewer changes.

Recall What happens to the rule when

or ? Total interest becomes , so is always false ⇒ never refactor — carrying the debt is free.

Recall In the exact tie

, do you refactor? No — keep the debt. Net saving is zero, so the tie breaks toward not spending the principal.

Recall Debt ratio formula?

remediation cost ÷ development cost (e.g. ).