← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

Boy Scout Rule

Code Quality Beginner
debt(d9/e3/b5/t5)
d9 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d9). The detection_hints explicitly state 'automated: no' and the code_pattern is 'technical debt accumulating without any clean-up in PRs' — there is no tool that detects violation of the Boy Scout Rule. Neglect accumulates silently over many commits and is only noticed when the codebase becomes painful to work in.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix describes small, incremental actions (rename a variable, extract a snippet, delete a dead comment). Correcting a pattern of ignoring the rule requires instilling a habit across the team and cleaning up accumulated debt, which is more than a one-liner but still localized — not a cross-cutting architectural refactor.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). The term applies_to all contexts (web, cli, queue-worker), meaning consistent neglect affects every work stream. The common_mistakes show it compounds across every PR and every developer's workflow, but it doesn't define the system's shape on its own — it's a cultural/process debt that slows many work streams without necessarily dictating architecture.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field explicitly states the canonical wrong belief: developers interpret the rule as licence for large refactors during any ticket, when it means only small, incremental improvements. This is a documented and commonly learned gotcha — notable but not catastrophically counterintuitive compared to analogous concepts.

About DEBT scoring →

Also Known As

leave it better opportunistic refactoring campsite rule

TL;DR

Always leave the codebase slightly cleaner than you found it — small, consistent improvements prevent entropy accumulation.

Explanation

Robert C. Martin's Boy Scout Rule (from Robert Baden-Powell's 'Leave the campsite cleaner than you found it') applied to code: whenever you touch a file, make a small improvement — rename a confusing variable, extract a long method, remove a dead comment. These micro-improvements compound over time, keeping technical debt from accumulating. The rule is pragmatic: improvements should be small and risk-proportionate, not full refactors in the middle of a feature branch.

Common Misconception

The boy scout rule justifies large refactors during any ticket. It means small, incremental improvements — fix a bad variable name, extract a method, add a missing test — not a full rewrite triggered by touching a related file.

Why It Matters

The Boy Scout Rule — always leave code cleaner than you found it — prevents the gradual decay that turns working code into legacy code. Each small improvement compounds; each ignored smell compounds too.

Common Mistakes

  • Interpreting the rule as licence to refactor everything you touch — scope improvements to what is directly relevant.
  • Making cleanup changes in the same commit as feature changes — separate commits make blame and rollback cleaner.
  • Skipping the rule under deadline pressure consistently — this is exactly when debt accumulates fastest.
  • Applying it only to formatting and ignoring structural improvements like extracting methods or removing duplication.

Code Examples

💡 Note
The rule isn't to refactor everything you see — improve only the immediate area you're already touching.
✗ Vulnerable
// Leaving broken-window code untouched:
function calcTtl($d, $t) { // Cryptic names, never improved
    return $d * 86400 + $t; // What does this compute? Magic numbers too
}
✓ Fixed
// Leave the code cleaner than you found it — in the area you're already touching

// Before (you're fixing a bug in this method):
public function calculateTotal($c) {  // vague name
    $t = 0;                            // single-letter variable
    foreach($c as $i) $t += $i['p'];   // magic key 'p'
    return $t;
}

// After (bug fixed + scout cleanup — same PR, minimal scope):
public function calculateTotal(array $cartItems): float {
    return array_reduce(
        $cartItems,
        fn(float $total, array $item) => $total + $item['price'],
        0.0
    );
}

Added 15 Mar 2026
Edited 22 Mar 2026
Views 125
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 1 ping S 1 ping S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 1 ping M 0 pings T 1 ping W 0 pings T 0 pings F 0 pings S 1 ping S 1 ping M 0 pings T 1 ping W 0 pings T 0 pings F 0 pings S 1 ping S 1 ping M 0 pings T 0 pings W 1 ping T 1 ping F 0 pings S
No pings yet today
Sogou 1
Amazonbot 12 SEMrush 10 Scrapy 7 PetalBot 7 Google 6 Perplexity 6 ChatGPT 6 Ahrefs 5 Bing 4 Sogou 3 Applebot 3 Unknown AI 2 Meta AI 1 Twitter/X 1
crawler 70 crawler_json 3
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Low
⚡ Quick Fix
Leave every piece of code you touch slightly better than you found it — rename one unclear variable, extract one repeated snippet, delete one dead comment
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Technical debt accumulating without any clean-up in PRs; no refactoring commits alongside feature work
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Medium Context: File


✓ schema.org compliant