clean-code
Skill3 starsChanged 8 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.
108 other projects use a version of this.
Adopted by
Most recently taken up by
- sbluemin/fleet-harnesstheir own version, first seen Nov 8, 2026
- nohemi20231/design-skillstheir own version, first seen Nov 8, 2026
- MammadovEshgin/clean-code-skilltheir own version, first seen Nov 8, 2026
- Mahesh-Bishnoi/skillstheir own version, first seen Nov 8, 2026
- Bruno-Cunha-Souza/ValarMindSkillstheir own version, first seen Nov 8, 2026
- kana-consultant/kana-best-practice-engineeringtheir own version, first seen Nov 8, 2026
Used with
Projects with it also use intelligent-routing, nextjs-react-expert and 9 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.
SKB3002Skillintelligent-routing
Automatic agent selection and intelligent task routing. Analyzes user requests and automatically selects the best specialist agent(s) without requiring explicit user mentions.
Also in 5 projects that use this
SKB3002Skillnextjs-react-expert
React and Next.js performance optimization from Vercel Engineering. Use when building React components, optimizing performance, eliminating waterfalls, reducing bundle size, reviewing code for performance issues, or implementing server/client-side optimizations.
Also in 3 projects that use this
xfstudioSkillbash-pro
Master of defensive Bash scripting for production automation, CI/CD
Also in 4 projects that use this
xfstudioSkillcode-refactoring-tech-debt
You are a technical debt expert specializing in identifying, quantifying, and prioritizing technical debt in software projects. Analyze the codebase to uncover debt, assess its impact, and create acti
Also in 4 projects that use this
flying-diceSkillclean-code-review
Multi-agent clean code audit — each principle gets its own agent
Also in 3 projects that use this
goca-seSkillbatch-operations
Apply a change safely across many files — refactors touching more than 5 files, library or API migrations, project-wide renames of symbols/imports/paths, or adding boilerplate to many files. Use when "do it all at once" risks context overflow or silent failures.
Also in 3 projects that use this
- +4 more from xfstudio
Other versions108 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 108
- superplanehq/superplane★ 9.1ksame name
- vudovn/ag-kit★ 8.2ksame name
- vudovn/antigravity-kit★ 8.2ksame name
- Openpanel-dev/openpanel★ 7.3ksame name
- ciembor/agent-rules-books★ 2.8ksame name
- wondelai/skills★ 2.6ksame name
- decebals/claude-code-java★ 763same name
- operately/operately★ 618same name
- liza-mas/liza★ 418same name
- Mindrally/skills★ 275same name
98 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 repository48 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
- todoSkill
- 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 101 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 101 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.

