Clean Code Skill
This skill embodies the principles of "Clean Code" by Robert C. Martin (Uncle Bob). Use it to transform "code that works" into "code that is clean."
🧠 Core Philosophy
"Code is clean if it can be read, and enhanced by a developer other than its original author." — Grady Booch
When to Use
Use this skill when:
- Writing new code: To ensure high quality from the start.
- Reviewing Pull Requests: To provide constructive, principle-based feedback.
- Refactoring legacy code: To identify and remove code smells.
- Improving team standards: To align on industry-standard best practices.
1. Meaningful Names
- Use Intention-Revealing Names:
elapsedTimeInDays instead of d.
- Avoid Disinformation: Don't use
accountList if it's actually a Map.
- Make Meaningful Distinctions: Avoid
ProductData vs ProductInfo.
- Use Pronounceable/Searchable Names: Avoid
genymdhms.
- Class Names: Use nouns (
Customer, WikiPage). Avoid Manager, Data.
- Method Names: Use verbs (
postPayment, deletePage).
2. Functions
- Small!: Functions should be shorter than you think.
- Do One Thing: A function should do only one thing, and do it well.
- One Level of Abstraction: Don't mix high-level business logic with low-level details (like regex).
- Descriptive Names:
isPasswordValid is better than check.
- Arguments: 0 is ideal, 1-2 is okay, 3+ requires a very strong justification.
- No Side Effects: Functions shouldn't secretly change global state.
3. Comments
4. Formatting
- The Newspaper Metaphor: High-level concepts at the top, details at the bottom.
- Vertical Density: Related lines should be close to each other.
- Distance: Variables should be declared near their usage.
- Indentation: Essential for structural readability.
5. Objects and Data Structures
- Data Abstraction: Hide the implementation behind interfaces.
- The Law of Demeter: A module should not know about the innards of the objects it manipulates. Avoid
a.getB().getC().doSomething().
- Data Transfer Objects (DTO): Classes with public variables and no functions.
6. Error Handling
- Use Exceptions instead of Return Codes: Keeps logic clean.
- Write Try-Catch-Finally First: Defines the scope of the operation.
- Don't Return Null: It forces the caller to check for null every time.
- Don't Pass Null: Leads to
NullPointerException.
7. Unit Tests
- The Three Laws of TDD:
- Don't write production code until you have a failing unit test.
- Don't write more of a unit test than is sufficient to fail.
- Don't write more production code than is sufficient to pass the failing test.
- F.I.R.S.T. Principles: Fast, Independent, Repeatable, Self-Validating, Timely.
8. Classes
- Small!: Classes should have a single responsibility (SRP).
- The Stepdown Rule: We want the code to read like a top-down narrative.
9. Smells and Heuristics
- Rigidity: Hard to change.
- Fragility: Breaks in many places.
- Immobility: Hard to reuse.
- Viscosity: Hard to do the right thing.
- Needless Complexity/Repetition.
🛠️ Implementation Checklist
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Source: sickn33/agentic-awesome-skills → skills/clean-code/SKILL.md
Also appears in: sickn33/agentic-awesome-skills/plugins/agentic-awesome-skills/skills/clean-code/SKILL.md, sickn33/agentic-awesome-skills/plugins/agentic-awesome-skills-claude/skills/clean-code/SKILL.md
1---2name: clean-code3description: This skill embodies the principles of \"Clean Code\" by Robert C. Martin (Uncle Bob). Use it to transform \"code that works\" into \"code that is clean.\"4---5
6
7# Clean Code Skill
8
9This skill embodies the principles of "Clean Code" by Robert C. Martin (Uncle Bob). Use it to transform "code that works" into "code that is clean."
10
11## 🧠 Core Philosophy
12> "Code is clean if it can be read, and enhanced by a developer other than its original author." — Grady Booch
13
14## When to Use
15Use this skill when:
16- **Writing new code**: To ensure high quality from the start.
17- **Reviewing Pull Requests**: To provide constructive, principle-based feedback.
18- **Refactoring legacy code**: To identify and remove code smells.
19- **Improving team standards**: To align on industry-standard best practices.
20
21## 1. Meaningful Names
22- **Use Intention-Revealing Names**: `elapsedTimeInDays` instead of `d`.
23- **Avoid Disinformation**: Don't use `accountList` if it's actually a `Map`.
24- **Make Meaningful Distinctions**: Avoid `ProductData` vs `ProductInfo`.
25- **Use Pronounceable/Searchable Names**: Avoid `genymdhms`.
26- **Class Names**: Use nouns (`Customer`, `WikiPage`). Avoid `Manager`, `Data`.
27- **Method Names**: Use verbs (`postPayment`, `deletePage`).
28
29## 2. Functions
30- **Small!**: Functions should be shorter than you think.
31- **Do One Thing**: A function should do only one thing, and do it well.
32- **One Level of Abstraction**: Don't mix high-level business logic with low-level details (like regex).
33- **Descriptive Names**: `isPasswordValid` is better than `check`.
34- **Arguments**: 0 is ideal, 1-2 is okay, 3+ requires a very strong justification.
35- **No Side Effects**: Functions shouldn't secretly change global state.
36
37## 3. Comments
38- **Don't Comment Bad Code—Rewrite It**: Most comments are a sign of failure to express ourselves in code.
39- **Explain Yourself in Code**:
40 ```python
41 # Check if employee is eligible for full benefits
42 if employee.flags & HOURLY and employee.age > 65:
43 ```
44 vs
45 ```python
46 if employee.isEligibleForFullBenefits():
47 ```
48- **Good Comments**: Legal, Informative (regex intent), Clarification (external libraries), TODOs.
49- **Bad Comments**: Mumbling, Redundant, Misleading, Mandated, Noise, Position Markers.
50
51## 4. Formatting
52- **The Newspaper Metaphor**: High-level concepts at the top, details at the bottom.
53- **Vertical Density**: Related lines should be close to each other.
54- **Distance**: Variables should be declared near their usage.
55- **Indentation**: Essential for structural readability.
56
57## 5. Objects and Data Structures
58- **Data Abstraction**: Hide the implementation behind interfaces.
59- **The Law of Demeter**: A module should not know about the innards of the objects it manipulates. Avoid `a.getB().getC().doSomething()`.
60- **Data Transfer Objects (DTO)**: Classes with public variables and no functions.
61
62## 6. Error Handling
63- **Use Exceptions instead of Return Codes**: Keeps logic clean.
64- **Write Try-Catch-Finally First**: Defines the scope of the operation.
65- **Don't Return Null**: It forces the caller to check for null every time.
66- **Don't Pass Null**: Leads to `NullPointerException`.
67
68## 7. Unit Tests
69- **The Three Laws of TDD**:
70 1. Don't write production code until you have a failing unit test.
71 2. Don't write more of a unit test than is sufficient to fail.
72 3. Don't write more production code than is sufficient to pass the failing test.
73- **F.I.R.S.T. Principles**: Fast, Independent, Repeatable, Self-Validating, Timely.
74
75## 8. Classes
76- **Small!**: Classes should have a single responsibility (SRP).
77- **The Stepdown Rule**: We want the code to read like a top-down narrative.
78
79## 9. Smells and Heuristics
80- **Rigidity**: Hard to change.
81- **Fragility**: Breaks in many places.
82- **Immobility**: Hard to reuse.
83- **Viscosity**: Hard to do the right thing.
84- **Needless Complexity/Repetition**.
85
86## 🛠️ Implementation Checklist
87- [ ] Is this function smaller than 20 lines?
88- [ ] Does this function do exactly one thing?
89- [ ] Are all names searchable and intention-revealing?
90- [ ] Have I avoided comments by making the code clearer?
91- [ ] Am I passing too many arguments?
92- [ ] Is there a failing test for this change?
93
94## Limitations
95- Use this skill only when the task clearly matches the scope described above.
96- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
97- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
98
99---
100
101**Source:** [`sickn33/agentic-awesome-skills`](https://github.com/sickn33/agentic-awesome-skills) → `skills/clean-code/SKILL.md`
102
103**Also appears in:** `sickn33/agentic-awesome-skills/plugins/agentic-awesome-skills/skills/clean-code/SKILL.md`, `sickn33/agentic-awesome-skills/plugins/agentic-awesome-skills-claude/skills/clean-code/SKILL.md`