# Technical Debt Exercises

## Exercise 1: Principal vs Interest

**Task:** A payment service has 2000 lines in one file. Every bug fix or feature touches it. Fixing it properly would take 2 sprints. Each change currently takes 2x longer due to complexity.

Estimate: (a) Principal (sprint-equivalent), (b) Interest per quarter (assuming 8 changes/quarter), (c) Break-even: after how many quarters does interest exceed principal?

**Validation:**
- [ ] Principal = 2 sprints
- [ ] Interest = 8 changes × some multiplier (e.g., 1 extra day each = 8 days)
- [ ] Break-even calculation is coherent

**Hints:**
1. Principal = one-time cost to fix
2. Interest = extra cost per touch × number of touches
3. When does cumulative interest > principal?

---

## Exercise 2: Quadrant Classification

**Task:** Classify each into Fowler's quadrant (prudent/reckless × deliberate/inadvertent):

1. Team uses `any` everywhere in TypeScript to ship fast; never revisits
2. Team picks a framework they've never used; architecture turns out wrong
3. Team defers a DB migration to next quarter with a written ticket
4. Copy-paste from Stack Overflow without understanding; causes bugs later

**Validation:**
- [ ] (1) Reckless deliberate
- [ ] (2) Prudent or reckless inadvertent
- [ ] (3) Prudent deliberate
- [ ] (4) Reckless inadvertent (or reckless deliberate if they knew)

**Hints:**
1. Deliberate = they knew they were taking a shortcut
2. Prudent = they planned to pay it back
3. "Never revisits" = reckless

---

## Exercise 3: Identify and Measure

**Task:** Pick a module (real or hypothetical). List 3 code smells, 2 metrics you'd track, and 1 business impact you'd report.

**Validation:**
- [ ] Smells are specific (e.g., "300-line function", "duplicated validation logic")
- [ ] Metrics are measurable (complexity, coverage, cycle time)
- [ ] Business impact is in stakeholder language (time, risk, cost)

**Hints:**
1. Smells: length, duplication, nesting, naming
2. Metrics: sonar/ESLint complexity, test coverage, Jira cycle time
3. Impact: "Feature X takes 2 days longer" or "Bugs in payment flow"

---

## Exercise 4: Pitch to Stakeholders

**Task:** Write a short pitch (5–7 sentences) to get 1 sprint for tech debt paydown. Include: problem, current cost, proposed fix, and what unlocks after.

**Validation:**
- [ ] States the problem in business terms
- [ ] Quantifies cost (time, risk, or money)
- [ ] Describes the fix at a high level
- [ ] Connects paydown to a positive outcome (faster features, fewer bugs)

**Hints:**
1. Avoid jargon — "slow to change" not "high cyclomatic complexity"
2. Use numbers: "20% of sprint on workarounds"
3. End with: "After this, we can deliver X faster"

---

## Exercise 5: Refactor vs Strangler vs Rewrite

**Task:** For each scenario, choose Refactor, Strangler Fig, or Rewrite. Justify in one sentence.

1. Auth logic is scattered across 10 files; needs centralization
2. Legacy PHP app; team wants to move to Node
3. One module has wrong abstractions; rest of system is fine

**Validation:**
- [ ] (1) Refactor — extract and consolidate
- [ ] (2) Strangler (or rewrite if very small) — gradually replace
- [ ] (3) Refactor — fix one module in place

**Hints:**
1. Refactor = improve in place
2. Strangler = build new around old, migrate incrementally
3. Rewrite = replace whole system; rare, high risk
