Leave it Better Than You Found it
Boy Scout, sharper.
Tidy the line that was touched. Cleanups belong in their own commit, not folded into a feature PR. The file already open for the bug fix is the file that gets tidied on the way past. The compounding effect of small, opportunistic cleanups is the corrective for software entropy.
Opinion
The compound interest on small cleanups is what separates a codebase you can still release from one you can't. The team that tidies one variable per commit ends a year with names that read like English. The team that defers tidying ends a year with the same code plus a year of accreted opacity. Martin's point in Clean Code is the same point, made from the opposite direction: the codebase is always either cleaner or dirtier than it was yesterday. The engineer chooses which.1
The bit I want to plant a flag on is the second sentence of the sub-line: cleanups travel in their own commit, not folded into the feature PR. Beck's Tidy First? is the modern reconciliation of the rule with the PR-discipline of P7 Short-Lived Branches.3 The cleanup belongs in a separate commit, ideally a separate PR, so the reviewer can read the structural change and the behaviour change without one obscuring the other. The rule survives. The diff hygiene survives. Both belong.
Sandi Metz's “Wrong Abstraction” is the qualifier inside the row: not every tidy is an improvement. In her words, “duplication is far cheaper than the wrong abstraction”, so a cleanup that extracts the wrong one leaves the code worse than it found it.4 Treat the rule as opportunistic, not compulsive: the file opened to fix the bug is the file tidied on the way past.7 The file that stayed closed is left alone.
Copy a note and link
Grab this short comment and drop it into a PR comment or an LLM chat to prompt the right change.
Tidy the line you touched. Don't smuggle a refactor into a feature PR. Do tidy the thing you came to fix. Cleanup goes in a separate commit (Beck's Tidy First). Behaviour change in another. Don't refactor what you can't test, and don't let the cleanup turn into a yak shave. /tenet/leave-it-better/P6
AI eyes only
Rule: tidy what you touched, no further. Behaviour changes and tidies travel in separate commits.
Reject: refactoring files unrelated to the requested change. Reject: bundling forty unrelated edits into the behaviour-change PR. Reject: declining to fix a small mess in the file you are already editing.
Generate: make the requested behaviour change first. Then in a separate commit, fix the adjacent rough edges in the same file. Each tidy is the minimum to remove a friction the next reader will feel.
Diagnostic: a reviewer should distinguish behaviour change from tidy in five seconds. If the diff mixes them, split.
Why?
- Compounding works. One small cleanup per commit ends a year with names that read like English. Deferring ends a year with the same code plus a year of accreted opacity.
- The cost is incidental. The unit is small (rename one variable, split one function) and the trigger is incidental: tidy only the file you opened to change.
- Beck's Tidy First? is the modern reconciliation: tidy in a separate commit, separate PR if large. The rule survives. The merge-conflict tax goes down.
- Pair with P1 Test-First Development. A green suite is a refactoring licence. Opportunistic cleanups stop being a leap of faith.
- The diff stays clean. The reviewer reads the tidy diff in two minutes, the feature diff in two minutes. Merge conflicts don't compound across feature and structural changes.
- Hunt and Thomas's “broken windows” idea in reverse: every cleaned window deters the next break. The codebase signal that says “we keep this clean” is what stops the next entropy increment.
- No cleanup sprints. The team that tidies as it goes never has to schedule the dedicated refactor week. The dedicated refactor week is the sign that the rule was skipped for a year.
Origins
The phrase belongs to Robert Baden-Powell, founder of the Scout Movement, whose 1941 farewell message asked Scouts to “try and leave this world a little better than you found it.” The campsite version, leave it cleaner than you found it, softened over the next half-century into the Scouting tradition every modern engineer who hears the term has half-met somewhere.
The software adaptation belongs to Robert C. Martin. Clean Code: A Handbook of Agile Software Craftsmanship (Prentice Hall, 2008) ch.1 page 14 has the canonical formulation: if we all checked in our code a little cleaner than when we checked it out.1 Martin re-published a one-page version as Essay 8 of 97 Things Every Programmer Should Know (O'Reilly, 2010), which is the link most engineers read.
The older intellectual root is Hunt and Thomas's “broken windows” ( The Pragmatic Programmer, 1999; Topic 3 “Software Entropy” in the 2019 edition).2 Hunt and Thomas wrote it as a prohibition with the action attached: don't live with broken windows, and fix bad designs, wrong decisions and poor code when you see them. Martin's rule scopes that action to the code being checked in: leave it a little cleaner than it was checked out. The two pieces fit together as one discipline.
Kent Beck's 2024 Tidy First? is the modern reconciliation.3 Beck's reply to the diff-hygiene critique: tidyings and behaviour changes belong in different commits, possibly different PRs. The rule survives. The merge-conflict tax goes down. Pair this with P7 Short-Lived Branches with AI+Human Review and the practice is operationalised: one PR, one behavioural change, plus a separate PR per structural tidy.
Sandi Metz's “Wrong Abstraction” (2016) is the qualifier inside the row.4 Duplication is far cheaper than the wrong abstraction, so not every cleanup leaves the code better. Metz's pragmatism is the corrective to compulsive cleanup. Treat the rule as opportunistic, not mandatory.
Quotes
The Boy Scouts of America have a simple rule that we can apply to our profession. Leave the campground cleaner than you found it. If we all checked-in our code a little cleaner than when we checked it out, the code simply could not rot.
Don’t Live with Broken Windows … Fix bad designs, wrong decisions, and poor code when you see them.
TF? distinguishes structure changes and behavior changes. … Constrain PRs to only contain one kind of change or the other. Never both.
prefer duplication over the wrong abstraction … Once an abstraction is proved wrong the best strategy is to re-introduce duplication and let it show you what’s right.
Evidence
19 external sources, ranked by author authority. The first five are the canon; expand to see the rest, including the qualifiers and the named opposers. Each links out to its primary source.
- 01Clean Code, ch.1SupportsThe canonical formulation: always check in a module cleaner than when you checked it out. Cites Baden-Powell as the source.
- 02One-page version of the Clean Code rule. The link most engineers read; CC-BY mirror in circulation.
- 03A prohibition with the action attached: don't live with broken windows; fix bad designs, wrong decisions and poor code when you see them. The intellectual root of Martin's rule.
- 04The modern reconciliation. Tidyings and behaviour changes belong in different commits. The rule survives, the merge-conflict tax goes down.
- 05The vocabulary the rule operates in. Each refactoring (Extract Function, Rename Variable, Inline) is a specific tidy the rule names.
- 06Names the practice the rule describes. Warns of yak-shaving and recommends “good judgement” on when to stop.
- 07“The Wrong Abstraction”QualifiesDuplication is far cheaper than the wrong abstraction, so a cleanup that extracts the wrong one leaves the code worse. The qualifier inside the row.
- 08Metz's wider refactoring-with-pragmatism teaching. Code that doesn't churn shouldn't be touched. Cleanup has a cost.
- 09Working Effectively with Legacy CodeQualifiesThe legacy-code corrective: refactoring without a regression suite is walking a tightrope without a net. Pair the rule with P1.
- 10Engineering Practices: “Small CLs”QualifiesRefactorings usually belong in a separate CL from feature changes or bug fixes, because reviewers understand each change more easily when they are separate. Small cleanups such as fixing a local variable name may stay inside the feature CL.
- 11“Separate each logical change into a separate patch.” The kernel's diff-hygiene rule that the Boy Scout rule has to negotiate around.
- 12“For each desired change, make the change easy (warning: this may be hard), then make the easy change.” The preparatory-refactoring idea: close cousin of the Boy Scout rule.
- 13Operational walk-through of Beck's tweet. The cleanup precedes the feature, not accompanies it. An alternative pattern to the in-place Boy Scout cleanup.
- 14“Boy Scout Rule and Its Limitations”QualifiesPractitioner critique of the rule's diff-creep failure mode. Useful as the qualifier the modern Tidy First reconciliation answers.
- 15PR-level qualification of the rule. The cleanup that bloats the PR is a cleanup the team won't merge.
- 16Argues the rule alone doesn't pay for the technical debt it nudges at. Useful as the broader-context qualifier. Pair with dedicated refactor budget.
- 17Refactoring Guru: RefactoringSupportsModern practitioner-friendly entry point to the refactoring vocabulary: a catalogue of code smells and the refactoring techniques that address them.
- 18Code improvements (readability, consistency, dead-code removal) were the most frequent kind of review comment in Microsoft code reviews: 165 of the 570 comments classified. Evidence that reviewers already ask for small cleanups; the paper does not discuss the Boy Scout rule.
- 19Companion essay in the same volume as Martin's Boy Scout entry. Argues that beautiful code is simple code; it does not discuss cleanup.
Nineteen sources, three stances. The supporters are Martin, Hunt & Thomas and Fowler: the cleanup canon. The qualifiers further down push the line that the rule needs nuance: not all code is worth tidying, tidy in separate commits, do not refactor without tests. The opposer is the Linux kernel's patch discipline: one logical change per patch, each one easy for reviewers to understand and verify. The steelman the case has to address.
Examples
Before new feature goes out; the adjacent pyramid stays.
function validateHedgehogRecord(hg: Hedgehog | null): boolean { if (hg) { if (hg.weightG >= 600) { return true; } } return false; } function recordHibernation(hg: Hedgehog, log: HibernationLog): void { if (validateHedgehogRecord(hg)) { log.entries.push({ id: hg.id, since: now }); } }
After same feature; three lines of guard clauses on the line we touched.
function validateHedgehogRecord(hg: Hedgehog | null): boolean { if (!hg) return false; if (hg.weightG < 600) return false; return true; } function recordHibernation(hg: Hedgehog, log: HibernationLog): void { if (validateHedgehogRecord(hg)) { log.entries.push({ id: hg.id, since: now }); } }
Before new feature goes out; the adjacent pyramid stays.
function validateHedgehogRecord(hg: Hedgehog | null): boolean { if (hg) { if (hg.weightG >= 600) { return true; } } return false; } function recordHibernation(hg: Hedgehog, log: HibernationLog): void { if (validateHedgehogRecord(hg)) { log.entries.push({ id: hg.id, since: now }); } }
After same feature; three lines of guard clauses on the line we touched.
function validateHedgehogRecord(hg: Hedgehog | null): boolean { if (!hg) return false; if (hg.weightG < 600) return false; return true; } function recordHibernation(hg: Hedgehog, log: HibernationLog): void { if (validateHedgehogRecord(hg)) { log.entries.push({ id: hg.id, since: now }); } }
Before new feature goes out; the adjacent pyramid stays.
function validateHedgehogRecord(hg) { if (hg) { if (hg.weightG >= 600) { return true; } } return false; } function recordHibernation(hg, log) { if (validateHedgehogRecord(hg)) { log.entries.push({ id: hg.id, since: now }); } }
After same feature; three lines of guard clauses on the line we touched.
function validateHedgehogRecord(hg) { if (!hg) return false; if (hg.weightG < 600) return false; return true; } function recordHibernation(hg, log) { if (validateHedgehogRecord(hg)) { log.entries.push({ id: hg.id, since: now }); } }
Before new feature goes out; the adjacent pyramid stays.
def validate_hedgehog_record(hg: Optional[Hedgehog]) -> bool: if hg is not None: if hg.weight_g >= 600: return True return False def record_hibernation(hg: Hedgehog, log: HibernationLog) -> None: if validate_hedgehog_record(hg): log.entries.append(LogEntry(id=hg.id, since=now))
After same feature; three lines of guard clauses on the line we touched.
def validate_hedgehog_record(hg: Optional[Hedgehog]) -> bool: if hg is None: return False if hg.weight_g < 600: return False return True def record_hibernation(hg: Hedgehog, log: HibernationLog) -> None: if validate_hedgehog_record(hg): log.entries.append(LogEntry(id=hg.id, since=now))
Before new feature goes out; the adjacent pyramid stays.
boolean validateHedgehogRecord(Hedgehog hg) { if (hg != null) { if (hg.weightG() >= 600) { return true; } } return false; } void recordHibernation(Hedgehog hg, HibernationLog log) { if (validateHedgehogRecord(hg)) { log.entries().add(new LogEntry(hg.id(), now)); } }
After same feature; three lines of guard clauses on the line we touched.
boolean validateHedgehogRecord(Hedgehog hg) { if (hg == null) return false; if (hg.weightG() < 600) return false; return true; } void recordHibernation(Hedgehog hg, HibernationLog log) { if (validateHedgehogRecord(hg)) { log.entries().add(new LogEntry(hg.id(), now)); } }
Before new feature goes out; the adjacent pyramid stays.
function validateHedgehogRecord(?Hedgehog $hg): bool { if ($hg !== null) { if ($hg->weightG >= 600) { return true; } } return false; } function recordHibernation(Hedgehog $hg, HibernationLog $log): void { if (validateHedgehogRecord($hg)) { $log->entries[] = new LogEntry(id: $hg->id, since: $now); } }
After same feature; three lines of guard clauses on the line we touched.
function validateHedgehogRecord(?Hedgehog $hg): bool { if ($hg === null) return false; if ($hg->weightG < 600) return false; return true; } function recordHibernation(Hedgehog $hg, HibernationLog $log): void { if (validateHedgehogRecord($hg)) { $log->entries[] = new LogEntry(id: $hg->id, since: $now); } }
Enforcement
Apply these rules in eslint.config.mjs. The full enforcement across every tenet lives on the implementation page.
| Rule | Tool | Catches |
|---|---|---|
| unused-imports/no-unused-imports | eslint-plugin-unused-imports | imports left after a refactor: the most common cleanup signal. Auto-fixes; the engineer never opens a fix-only PR. |
| unused-imports/no-unused-vars | eslint-plugin-unused-imports | variables declared and never used. Stops the dead-state-on-the-way-past pattern from compounding. |
| no-unreachable | ESLint core | code after return / throw: the dead-code signal the rule asks the engineer to clean. |
| no-empty | ESLint core | empty blocks left after refactor. Catches the “half-cleanup” shape; either restore behaviour or remove the block. |
| Husky commit-msg (one-type hook) | Husky commit-msg | commit headers that do not name exactly one Conventional Commits type, so every commit declares its kind: refactor for a tidy, feat or fix for a behaviour change. It reads the message, not the diff, so a commit that mixes the two under one type still needs the reviewer. |
| Conventional Commits | Conventional Commits | the commit-type taxonomy: feat / fix for behaviour, refactor / chore for structure. The vocabulary the hook reads. |
| @typescript-eslint/no-unused-vars | typescript-eslint | unused parameters and variables in TS source. |
eslint.config.mjsconfiguration snippet
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
import unusedImports from 'eslint-plugin-unused-imports';
export default defineConfig({
files: ['**/*.{ts,tsx}'],
languageOptions: { parser: tseslint.parser },
plugins: { 'unused-imports': unusedImports },
rules: {
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': 'error',
'no-unreachable': 'error',
'no-empty': ['error', { allowEmptyCatch: false }],
}
});Apply these rules in eslint.config.mjs. The full enforcement across every tenet lives on the implementation page.
| Rule | Tool | Catches |
|---|---|---|
| unused-imports/no-unused-imports | eslint-plugin-unused-imports | imports left after a refactor: the most common cleanup signal. Auto-fixes; the engineer never opens a fix-only PR. |
| unused-imports/no-unused-vars | eslint-plugin-unused-imports | variables declared and never used. Stops the dead-state-on-the-way-past pattern from compounding. |
| no-unreachable | ESLint core | code after return / throw: the dead-code signal the rule asks the engineer to clean. |
| no-empty | ESLint core | empty blocks left after refactor. Catches the “half-cleanup” shape; either restore behaviour or remove the block. |
| Husky commit-msg (one-type hook) | Husky commit-msg | commit headers that do not name exactly one Conventional Commits type, so every commit declares its kind: refactor for a tidy, feat or fix for a behaviour change. It reads the message, not the diff, so a commit that mixes the two under one type still needs the reviewer. |
| Conventional Commits | Conventional Commits | the commit-type taxonomy: feat / fix for behaviour, refactor / chore for structure. The vocabulary the hook reads. |
| @typescript-eslint/no-unused-vars | typescript-eslint | unused parameters and variables in TS source. |
eslint.config.mjsconfiguration snippet
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
import unusedImports from 'eslint-plugin-unused-imports';
export default defineConfig({
files: ['**/*.{ts,tsx}'],
languageOptions: { parser: tseslint.parser },
plugins: { 'unused-imports': unusedImports },
rules: {
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': 'error',
'no-unreachable': 'error',
'no-empty': ['error', { allowEmptyCatch: false }],
}
});Apply these rules in .husky/commit-msg. The full enforcement across every tenet lives on the implementation page.
| Rule | Tool | Catches |
|---|---|---|
| unused-imports/no-unused-imports | eslint-plugin-unused-imports | imports left after refactor. |
| no-unused-vars | ESLint core | variables declared and never used. |
| no-unreachable | ESLint core | code after return / throw. |
| no-empty | ESLint core | empty blocks left after refactor. |
| Husky commit-msg | Husky commit-msg | commit headers without exactly one Conventional Commits type. It reads the message, not the diff. |
| commitlint | Conventional Commits | the commit-type taxonomy. |
.husky/commit-msgconfiguration snippet
HEADER=$(head -n 1 "$1")
case "$HEADER" in
'Merge '*|'Revert "'*|'fixup! '*|'squash! '*) exit 0 ;;
esac
if ! printf '%s\n' "$HEADER" | grep -qE '^(feat|fix|refactor|style|test|docs|build|ci|chore|perf|revert)(\([^)]*\))?!?: '; then
echo "Name one Conventional Commits type: refactor for a tidy, feat or fix for a behaviour change. Split per Beck's Tidy First."
exit 1
fiApply these rules in pyproject.toml. The full enforcement across every tenet lives on the implementation page.
| Rule | Tool | Catches |
|---|---|---|
| F401 | Ruff (F401, F841: unused imports/variables) | unused imports. The most common cleanup signal; auto-fixes in --fix mode. |
| F841 | Ruff (F401, F841: unused imports/variables) | local variables assigned and never used. |
| ARG001-ARG005 | Ruff (ARG: unused arguments) | unused function and method arguments. Catches half-finished refactors. |
| ERA001 | Ruff (ERA001: eradicate) | commented-out code left from a refactor. The dead-prose signal Boy Scout asks to clean. |
| conventional-pre-commit | pre-commit | the commit-message format: rejects messages that do not follow Conventional Commits. It reads the message, not the diff, so it cannot detect a mixed commit. |
| vulture | vulture | dead-code analysis at PR time. Finds unused functions, classes and attributes across the files it scans, which Ruff's unused-import, unused-variable and unused-argument rules do not cover. |
pyproject.tomlconfiguration snippet
[tool.ruff.lint]
select = [
"F401",
"F841",
"E501",
"ERA001",
"ARG",
]
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["ARG"]Apply these rules in checkstyle.xml. The full enforcement across every tenet lives on the implementation page.
| Rule | Tool | Catches |
|---|---|---|
| UnusedImports | Checkstyle (UnusedImports, UnusedLocalVariable) | imports left after refactor. |
| UnusedLocalVariable | Checkstyle (UnusedImports, UnusedLocalVariable) | variables declared and never used. |
| UnusedPrivateField / UnusedFormalParameter | PMD (UnusedPrivateField, UnusedFormalParameter) | fields and parameters declared and never read. Common refactor residue; the rule asks to remove. |
| DLS_DEAD_LOCAL_STORE | SpotBugs (DEAD_LOCAL_STORE) | values written to local variables and never read again. |
| EmptyBlock / EmptyCatchBlock | Checkstyle (UnusedImports, UnusedLocalVariable) | empty blocks left after refactor. |
| S1135 (TODO tags) | SonarQube Java | TODO markers left after a partial cleanup. The half-finished signal Boy Scout asks to close. |
checkstyle.xmlconfiguration snippet
<?xml version="1.0"?>
<module name="Checker">
<module name="TreeWalker">
<module name="UnusedImports"/>
<module name="UnusedLocalVariable"/>
<module name="EmptyBlock"/>
<module name="EmptyCatchBlock"/>
</module>
</module>Apply these rules in .php-cs-fixer.dist.php. The full enforcement across every tenet lives on the implementation page.
| Rule | Tool | Catches |
|---|---|---|
| no_unused_imports | PHP-CS-Fixer | use statements left after refactor. Auto-fixes; never opens a fix-only PR. |
| no_useless_else | PHP-CS-Fixer | useless else after early return. The branching residue from incremental refactor. |
| no_useless_return | PHP-CS-Fixer | redundant return statements at the end of void functions. |
| deadCode (PHPStan level 4+) | PHPStan (deadCode, constructor.unusedParameter) | unreachable code paths. The deeper dead-code signal PHP-CS-Fixer can't see. |
| constructor.unusedParameter (PHPStan level 1+) | PHPStan (deadCode, constructor.unusedParameter) | constructor parameters declared and never used. Promoted parameters are skipped. |
| no_empty_statement | PHP-CS-Fixer | empty statements left after refactor. |
.php-cs-fixer.dist.phpconfiguration snippet
<?php
return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_empty_statement' => true,
'no_alias_functions' => true,
])
->setFinder(
(new PhpCsFixer\Finder())->in(__DIR__ . '/src')
);AI rules
.cursor/rules/p6-leave-it-better.mdc--- alwaysApply: true --- ## Prickles P6: Leave it Better Than You Found it Tidy the line you touched. The unit is small: rename one variable, split one function, delete one dead import. The trigger is incidental: tidy only the file you opened to change. Tidy in a separate commit. Beck's Tidy First rule: structural change and behaviour change belong in different commits, possibly different PRs. Don't refactor what you can't test. A green suite is a refactoring licence. Without one, the cleanup is walking a tightrope without a net. Don't let the cleanup grow into a yak shave. Fowler's “opportunistic refactoring” warning: every cleanup reveals another. Use good judgment on when to stop.
Repo layout, CI, and ESLint wiring for these paths live on /implementation, not repeated on every tenet.
Counter-argument
The strongest steelman is the diff-hygiene critique. The Linux kernel's Submitting Patches docs ask for each logical change in its own patch, and Google's engineering practices recommend refactorings in a separate CL from feature changes or bug fixes.5 Both give the same reason: a reviewer understands each change more easily when the changes are separate. Sandi Metz's “Wrong Abstraction” sharpens the point: duplication is far cheaper than the wrong abstraction, and a cleanup that extracts the wrong one leaves the code worse than the original mess.4 Michael Feathers extends the warning into Working Effectively with Legacy Code: refactoring without a regression suite is like “doing aerial gymnastics without a net.”6
Counter-argument retort
The diff-hygiene critique is sharpest when the cleanup obscures the behavioural change. Beck's Tidy First? answers the critique without abandoning the rule: tidy in a separate PR, never in the same diff that releases the feature.3 The reviewer reads the tidy diff in two minutes (no behavioural change, just structure) and the feature diff in two minutes (no structural change, just behaviour), and both PRs merge cleanly.
Metz's “Wrong Abstraction” is the second corrective. The compounding effect of small cleanups is real. The compounding effect of bad abstractions imposed in cleanup is worse. Apply the rule to names, splits, comment removals and dead-code deletions.8 Do not “introduce an abstraction” opportunistically. Pair this with A2 Three-Tier Hoisting and the rule of three: duplication earns its abstraction. Opportunistic abstraction is debt.
Feathers' legacy-code warning is the third: don't refactor what you can't test.6 The cleanup that breaks the production system is worse than the entropy it was trying to fix. The fix is not to skip cleanups. It is to pair the rule with P1 Test-First Development. A green suite is a refactoring licence. Without one, the Boy Scout walks the tightrope without a net.
In production work, the row that tidies one thing per commit produces a codebase the next engineer can deliver in. The row that doesn't produces a codebase the next engineer complains about and doesn't fix, on the grounds that the diff would be too large. Compounding works in both directions. The rule decides which.
Notes
- [1]Robert C. Martin: Clean Code: A Handbook of Agile Software Craftsmanship (Prentice Hall, 2008), ch.1 page 14. The canonical formulation: always check in a module cleaner than when you checked it out. Re-published as Essay 8 of 97 Things Every Programmer Should Know (O’Reilly, 2010).
- [2]Andy Hunt & Dave Thomas: The Pragmatic Programmer, 20th Anniversary Edition (Addison-Wesley, 2019), Topic 3 “Software Entropy”. Tip 5 “Don't Live with Broken Windows”: “Fix bad designs, wrong decisions, and poor code when you see them.” Martin's rule scopes that action to the code being checked in.
- [3]Kent Beck: Tidy First? A Personal Exercise in Empirical Software Design (O'Reilly, 2024). The modern reconciliation: tidyings and behaviour changes belong in different commits, possibly different PRs. The rule survives and the merge-conflict tax goes down.
- [4]Sandi Metz: “The Wrong Abstraction” (sandimetz.com, 2016). The qualifier inside the row: “duplication is far cheaper than the wrong abstraction”. A cleanup that extracts the wrong abstraction leaves the code worse than the duplication it replaced.
- [5]Google: Engineering Practices documentation, “Small CLs”, section “Separate Out Refactorings”. Refactorings usually belong in a separate CL from feature changes or bug fixes: “It is much easier for reviewers to understand the changes introduced by each CL when they are separate.” Small cleanups such as fixing a local variable name may stay inside the feature CL.
- [6]Michael Feathers: Working Effectively with Legacy Code (Prentice Hall, 2004). The legacy-code corrective: refactoring without a regression suite is walking a tightrope without a net. The fix is to pair the rule with P1 Test-First.
- [7]Martin Fowler: “Opportunistic Refactoring” bliki entry. Names the practice the rule describes. Warns of yak-shaving (going down the rabbit hole) and recommends “good judgement” on when to stop.
- [8]Refactoring Guru: Refactoring summary page. The practitioner-friendly entry point to the refactoring vocabulary: its catalogue lists Extract Method, Inline Method and Rename Method, and names Comments and Dead Code among the code smells.