clean-code
Skill2 starsChanged 9 months agoCC0-1.0View on GitHub
Enforces clean code principles including meaningful naming, small focused functions, command-query separation, error handling with exceptions, and Kent Beck's four rules of simple design. Use when writing new code, refactoring existing code, reviewing pull requests for readability and maintainability, applying the Boy Scout Rule, or evaluating functions for single responsibility and appropriate abstraction level.
63 other projects use a version of this.
Adopted by
Most recently taken up by
- superplanehq/superplanetheir own version, first seen Oct 5, 2026
- JeffreyFerreiras/ai-skillstheir own version, first seen Oct 5, 2026
- sbluemin/fleet-harnesstheir own version, first seen Oct 4, 2026
- jd-solanki/krutrimboxtheir own version, first seen Sep 27, 2026
- samirpatil2000/skillstheir own version, first seen Sep 26, 2026
- btseee/clean-code-skillstheir own version, first seen Sep 25, 2026
Used with
Projects with it also use 2d-games, 3d-games and 7 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
tiendatworkSkill2d-games
2D game development principles. Sprites, tilemaps, physics, camera.
Also in 3 projects that use this
tiendatworkSkill3d-games
3D game development principles. Rendering, shaders, physics, cameras.
Also in 3 projects that use this
DIL8654Skilllogging-patterns
Keep logs structured, correlated, low-noise, and safe for production support. Use when adding operational logging, reviewing observability, or improving diagnostics in .NET services.
Also in 3 projects that use this
- +6 more from tiendatwork
Other versions63 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 63
- superplanehq/superplane★ 7.7ksame name
- ciembor/agent-rules-books★ 2.9ksame name
- wondelai/skills★ 2.3ksame name
- decebals/claude-code-java★ 747same name
- Mindrally/skills★ 266same name
- xenitV1/claude-code-maestro★ 229same name
- techygarg/lattice★ 197same name
- ratacat/claude-skills★ 56same name
- DGouron/review-flow★ 44same name
- kumaran-is/claude-code-onboarding★ 36same name
53 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository47 other files it gives its agents.
- 3d-printingSkill
- app-securitySkill
- architecture-designSkill
- aws-genai-lensSkill
- aws-well-architected-frameworkSkill
- aws-well-architectedSkill
- azure-well-architectedSkill
- blog-post-with-diagramsSkill
- clean-architectureSkill
- databricks-genie-spaces-best-practicesSkill
- data-visualization-guideSkill
- design-an-interfaceSkill
- design-patternsSkill
- domain-driven-designSkill
- dry-principleSkill
- edit-articleSkill
- event-driven-designSkill
- git-best-practicesSkill
- git-guardrails-claude-codeSkill
- grill-meSkill
- hexagonal-architectureSkill
- improve-codebase-architectureSkill
- language-conventions-source-en-docs-brSkill
- learn-electronicsSkill
- linked-dataSkill
- microservices-skillSkill
- object-oriented-programmingSkill
- oop-design-patternsSkill
- oreilly-design-referenceSkill
- organize-docs-from-zipSkill
- prd-to-issuesSkill
- prd-to-planSkill
- project-context-syncSkill
- request-refactor-planSkill
- rfc2119Skill
- scaffold-exercisesSkill
- semverSkill
- setup-pre-commitSkill
- solid-principlesSkill
- tddSkill
- triage-issueSkill
- ts-otp-awsSkill
- ubiquitous-languageSkill
- ux-design-principlesSkill
- write-a-prdSkill
- write-a-skillSkill
- yagni-principleSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
34 rules. 0 are common, 27 are distinctive, and 7 are very specific to this project.
0
Common
Most of the 59 edited versions we read keep these.
27
Distinctive
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 27
MUST use intention-revealing names — the name tells WHY it exists, WHAT it does, HOW it's used
- Distinctive: line 28
MUST use pronounceable, searchable names — avoid abbreviations and single-letter variables (except loop counters)
- Very specific: line 29
MUST use nouns for classes (Order, ShippingPolicy) and verbs for methods (calculateTotal, validateAddress)
- Very specific: line 30
MUST pick one word per concept and use it consistently: don't mix fetch, retrieve, get for the same operation
- Very specific: line 31
MUST NOT use Hungarian notation, type prefixes, or member prefixes (strName, m_count)
- Distinctive: line 32
SHOULD use domain vocabulary — names from the problem domain or solution domain, never invented jargon
- Distinctive: line 47
MUST do one thing — if a function does more than one thing, extract the other things
- Distinctive: line 48
MUST operate at one level of abstraction — don't mix high-level orchestration with low-level details
- Distinctive: line 49
SHOULD follow the Stepdown Rule: read like a top-down narrative, each function introducing the next level of detail
- Distinctive: line 50
SHOULD have as few arguments as possible — zero (niladic) is ideal.
- Distinctive: line 51
MUST NOT use boolean flag arguments — they signal the function does two things.
- Distinctive: line 52
SHOULD be small enough to fit in your working memory — but prioritize clarity over arbitrary line counts
- Distinctive: line 110
MUST NOT create hybrids — half object, half data structure — that have the worst of both worlds
- Distinctive: line 111
SHOULD use objects when new types are more likely than new operations
- Distinctive: line 112
SHOULD use data structures when new operations are more likely than new types
- Very specific: line 113
MUST respect the Law of Demeter — no train wrecks: a.getB().getC().doSomething()
- Distinctive: line 121
MUST use exceptions instead of error return codes — exceptions separate the happy path from error handling
- Very specific: line 122
MUST write try-catch-finally first when the function involves operations that can fail
- Distinctive: line 123
SHOULD use unchecked exceptions — checked exceptions violate OCP (every catch clause in the call chain must be updated)
- Very specific: line 124
MUST NOT return null — use Null Object pattern, Optional/Maybe, or throw an exception
- Very specific: line 125
MUST NOT pass null as a function argument — there's no reasonable expectation for handling it
- Distinctive: line 126
SHOULD create exception classes organized by how callers HANDLE them, not by their source
- Distinctive: line 147
Write a failing test before writing any production code
- Distinctive: line 148
Write only enough of a test to demonstrate a failure
- Distinctive: line 149
Write only enough production code to make the failing test pass
- Distinctive: line 161
MUST test one concept per test — multiple assertions are fine if they all verify the same concept
- Distinctive: line 162
MUST NOT test private methods directly — test through the public interface
- Distinctive: line 183
SHOULD write a working solution first, then refactor incrementally
- Distinctive: line 184
MUST have tests in place before refactoring — TDD provides the safety net
- Distinctive: line 185
SHOULD apply the Boy Scout Rule: leave the code cleaner than you found it — small improvements compound over time
- Distinctive: line 186
SHOULD prefer tidying (small, safe structural improvements) as a separate step from feature work (Beck, *Tidy First?*)
- Distinctive: line 202
SHOULD apply clean code principles as guidelines balanced by context, not as rigid dogma
- Distinctive: line 203
SHOULD NOT fragment a clear 20-line function into five 4-line functions if it reduces readability
- Distinctive: line 209
When writing or reviewing code, verify:
“Common” is measured: kept by at least 6 in 10 of the 59 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Clean Code
Reference: Clean Code (Martin), Tidy First? (Beck), A Philosophy of Software Design (Ousterhout), Refactoring (Fowler)
When to Apply
- Writing new functions, classes, or modules
- Refactoring existing code for readability and maintainability
- Reviewing pull requests for naming, structure, and clarity
- Deciding whether to add a comment or improve the code instead
- Handling errors and edge cases in application code
- Evaluating whether code complexity is justified
Naming
"If a name requires a comment, it does not reveal its intent."
Rules
- MUST use intention-revealing names — the name tells WHY it exists, WHAT it does, HOW it's used
- MUST use pronounceable, searchable names — avoid abbreviations and single-letter variables (except loop counters)
- MUST use nouns for classes (
Order,ShippingPolicy) and verbs for methods (calculateTotal,validateAddress) - MUST pick one word per concept and use it consistently: don't mix
fetch,retrieve,getfor the same operation - MUST NOT use Hungarian notation, type prefixes, or member prefixes (
strName,m_count) - SHOULD use domain vocabulary — names from the problem domain or solution domain, never invented jargon
| Bad | Good | Why |
d | elapsedTimeInDays | Intention-revealing |
genymdhms | generationTimestamp | Pronounceable |
accountList | accounts | Don't encode the container type |
Manager, Processor, Handler | Specific name for the actual responsibility | Avoid meaningless suffixes |
Functions
Rules
- MUST do one thing — if a function does more than one thing, extract the other things
- MUST operate at one level of abstraction — don't mix high-level orchestration with low-level details
- SHOULD follow the Stepdown Rule: read like a top-down narrative, each function introducing the next level of detail
- SHOULD have as few arguments as possible — zero (niladic) is ideal; three or more requires justification
- MUST NOT use boolean flag arguments — they signal the function does two things; split into two functions
- SHOULD be small enough to fit in your working memory — but prioritize clarity over arbitrary line counts
Command-Query Separation (CQS)
Functions MUST either do something (command — changes state, returns void) or answer something (query — returns a value, no side effects). Never both.
# BAD — command and query mixed
def set_and_get_previous(value):
previous = self.value
self.value = value
return previous
# GOOD — separated
def get_value(self): # query
return self.value
def set_value(self, value): # command
self.value = valueComments
"Don't comment bad code — rewrite it." (Kernighan & Plaugher)
Acceptable Comments
| Type | Example | Why |
| Legal headers | // Copyright 2024 Acme Corp | Required by policy |
| Explanation of intent | // Use binary search because list is always sorted by insertion order | The code shows WHAT; the comment explains WHY |
| Warning of consequences | // This test takes 30 minutes to run | Prevents accidental execution |
| TODO markers | // TODO(#1234): Replace with batch API when available | Tracks known improvement with issue reference |
| API documentation | Javadoc/JSDoc for public APIs | Contract documentation for consumers |
Comments That MUST Be Avoided
- Redundant comments that restate the code:
i++; // increment i - Misleading comments that describe what the code SHOULD do but doesn't
- Commented-out code — version control preserves history; delete dead code
- Journal comments — git log tracks changes; don't maintain a changelog in code
- Closing brace comments — if you need them, your function is too long
Objects vs Data Structures
Objects and data structures are diametrically opposed (Martin). Choose deliberately.
| Objects | Data Structures | |
| Expose | Behavior (methods) | Data (fields) |
| Hide | Data (private state) | Nothing |
| Easy to add | New types (add new class) | New functions (add function operating on all types) |
| Hard to add | New behavior (must change all types) | New types (must change all functions) |
- MUST NOT create hybrids — half object, half data structure — that have the worst of both worlds
- SHOULD use objects when new types are more likely than new operations
- SHOULD use data structures when new operations are more likely than new types
- MUST respect the Law of Demeter — no train wrecks:
a.getB().getC().doSomething()
Error Handling
Rules
- MUST use exceptions instead of error return codes — exceptions separate the happy path from error handling
- MUST write
try-catch-finallyfirst when the function involves operations that can fail - SHOULD use unchecked exceptions — checked exceptions violate OCP (every catch clause in the call chain must be updated)
- MUST NOT return
null— use Null Object pattern, Optional/Maybe, or throw an exception - MUST NOT pass
nullas a function argument — there's no reasonable expectation for handling it - SHOULD create exception classes organized by how callers HANDLE them, not by their source
# BAD — checking null return
user = repository.find_by_id(id)
if user is not None:
# do something
# GOOD — exception or Optional
user = repository.find_by_id(id) # raises NotFoundError
# or
user = repository.find_by_id(id) # returns Optional<User>
user.if_present(lambda u: process(u))Unit Tests
TDD Three Laws
- Write a failing test before writing any production code
- Write only enough of a test to demonstrate a failure
- Write only enough production code to make the failing test pass
F.I.R.S.T. Principles
| Principle | Rule |
| Fast | Tests MUST run quickly — slow tests don't get run |
| Independent | Tests MUST NOT depend on each other or on execution order |
| Repeatable | Tests MUST produce the same result in any environment |
| Self-Validating | Tests MUST have a boolean output (pass/fail) — no manual log inspection |
| Timely | Tests SHOULD be written just before the production code (TDD) |
- MUST test one concept per test — multiple assertions are fine if they all verify the same concept
- MUST NOT test private methods directly — test through the public interface
Kent Beck's Four Rules of Simple Design
In priority order:
- Passes all the tests — a system that can't be verified MUST NOT be deployed
- Reveals intention — good names, small functions, standard patterns make the code self-documenting
- No duplication — every piece of knowledge has a single, authoritative representation
- Fewest elements — minimize classes and methods; counterbalance against over-decomposition
Rules 2–4 are applied during refactoring under the safety net of rule 1.
Successive Refinement
"To write clean code, you must first write dirty code and then clean it."
- SHOULD write a working solution first, then refactor incrementally
- MUST have tests in place before refactoring — TDD provides the safety net
- SHOULD apply the Boy Scout Rule: leave the code cleaner than you found it — small improvements compound over time
- SHOULD prefer tidying (small, safe structural improvements) as a separate step from feature work (Beck, Tidy First?)
Balancing Clean Code with Pragmatism
What Holds Up (2024 consensus)
Naming principles, SRP for functions, CQS, F.I.R.S.T. test principles, error handling with exceptions, the Boy Scout Rule, objects vs data structures distinction.
What Is Debated
- Extreme function size ("2–4 lines") can produce unreadable names and excessive indirection — prioritize clarity over arbitrary limits
- Performance in hot paths — Muratori demonstrated that Clean Code structural rules can produce 10–25x slower code in performance-critical scenarios; optimize hot paths pragmatically
- Deep modules (Ousterhout) — sometimes a larger function with a simple interface is better than many tiny functions that fragment the logic
- SHOULD apply clean code principles as guidelines balanced by context, not as rigid dogma
- SHOULD NOT fragment a clear 20-line function into five 4-line functions if it reduces readability
Checklist
When writing or reviewing code, verify:
- Names are intention-revealing, pronounceable, and consistent across the codebase
- Functions do one thing at one level of abstraction
- CQS is respected — functions either change state OR return a value, not both
- No commented-out code, redundant comments, or journal entries
- Comments explain WHY (intent), not WHAT (code restates itself)
- Error handling uses exceptions, not return codes; no null returns or null parameters
- Tests follow F.I.R.S.T. principles and cover one concept each
- No hybrids — objects hide data and expose behavior, or data structures expose data
- Law of Demeter is respected — no train wreck method chains
- Code has been tidied after getting it working — Boy Scout Rule applied
Key References
| Book | Author(s) | Publisher | Year |
| Clean Code | Robert C. Martin | Pearson | 2008 |
| Refactoring (2nd ed.) | Martin Fowler | Addison-Wesley | 2018 |
| A Philosophy of Software Design (2nd ed.) | John Ousterhout | Stanford | 2021 |
| Tidy First? | Kent Beck | O'Reilly | 2023 |
| Code That Fits in Your Head | Mark Seemann | Addison-Wesley | 2021 |
| Five Lines of Code | Christian Clausen | Manning | 2021 |
| The Pragmatic Programmer (2nd ed.) | Hunt & Thomas | Addison-Wesley | 2020 |
| Implementation Patterns | Kent Beck | Addison-Wesley | 2007 |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

