Clean Code Reference
A comprehensive reference for writing clean, maintainable code based on Robert Martin's "Clean Code" and related works. This skill provides language-agnostic principles with examples that apply to any programming language.
When This Skill Activates
This skill automatically activates when you:
- Review code for quality or maintainability
- Need guidance on naming conventions
- Discuss refactoring or code smells
- Apply SOLID principles
- Improve code readability or structure
- Write or review unit tests
Quick Reference
SOLID Principles
| Principle |
Summary |
Violation Sign |
| Single Responsibility (SRP) |
One reason to change |
Class does too many things |
| Open/Closed (OCP) |
Open for extension, closed for modification |
Modifying existing code for new features |
| Liskov Substitution (LSP) |
Subtypes must be substitutable |
Subclass breaks parent behavior |
| Interface Segregation (ISP) |
No forced dependencies on unused methods |
Fat interfaces |
| Dependency Inversion (DIP) |
Depend on abstractions, not concretions |
High-level modules import low-level |
Clean Code Practices
| Practice |
Key Points |
| Meaningful Names |
Intention-revealing, pronounceable, searchable |
| Functions |
Small, do one thing, one level of abstraction |
| Comments |
Code should be self-documenting; comments explain why, not what |
| Formatting |
Consistent style, vertical density, horizontal alignment |
| Error Handling |
Exceptions over error codes, fail fast, don't return null |
| Unit Testing |
F.I.R.S.T. principles, one assert per test, test behavior |
| Code Smells |
Recognition and refactoring of common problems |
| Boy Scout Rule |
Leave code cleaner than you found it |
The Boy Scout Rule
"Leave the campground cleaner than you found it."
Every time you touch code, make it a little better. Small, incremental improvements compound over time.
Code Quality Checklist
Before committing code, verify:
Language Translation Notes
Examples use generic pseudocode. Adapt to your language:
- PHP:
class, function, ->, type hints
- JavaScript/TypeScript:
class, arrow functions, .
- Python:
class, def, ., type hints
- Java/C#: Direct mapping with access modifiers
Based on concepts from "Clean Code: A Handbook of Agile Software Craftsmanship" by Robert C. Martin, 2008.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: clean-code-53description: Clean Code principles and practices reference based on Robert Martin's work. Use this skill when reviewing code quality, naming conventions, refactoring, or applying SOLID principles. Auto-activates for code smell detection, style improvements, and maintainability concerns. Use when this capability is needed.4---56# Clean Code Reference78A comprehensive reference for writing clean, maintainable code based on Robert Martin's "Clean Code" and related works. This skill provides language-agnostic principles with examples that apply to any programming language.910## When This Skill Activates1112This skill automatically activates when you:13- Review code for quality or maintainability14- Need guidance on naming conventions15- Discuss refactoring or code smells16- Apply SOLID principles17- Improve code readability or structure18- Write or review unit tests1920## Quick Reference2122### SOLID Principles23| Principle | Summary | Violation Sign |24|-----------|---------|----------------|25| [Single Responsibility (SRP)](solid/single-responsibility.md) | One reason to change | Class does too many things |26| [Open/Closed (OCP)](solid/open-closed.md) | Open for extension, closed for modification | Modifying existing code for new features |27| [Liskov Substitution (LSP)](solid/liskov-substitution.md) | Subtypes must be substitutable | Subclass breaks parent behavior |28| [Interface Segregation (ISP)](solid/interface-segregation.md) | No forced dependencies on unused methods | Fat interfaces |29| [Dependency Inversion (DIP)](solid/dependency-inversion.md) | Depend on abstractions, not concretions | High-level modules import low-level |3031### Clean Code Practices32| Practice | Key Points |33|----------|------------|34| [Meaningful Names](practices/meaningful-names.md) | Intention-revealing, pronounceable, searchable |35| [Functions](practices/functions.md) | Small, do one thing, one level of abstraction |36| [Comments](practices/comments.md) | Code should be self-documenting; comments explain why, not what |37| [Formatting](practices/formatting.md) | Consistent style, vertical density, horizontal alignment |38| [Error Handling](practices/error-handling.md) | Exceptions over error codes, fail fast, don't return null |39| [Unit Testing](practices/unit-testing.md) | F.I.R.S.T. principles, one assert per test, test behavior |40| [Code Smells](practices/code-smells.md) | Recognition and refactoring of common problems |41| [Boy Scout Rule](practices/boy-scout-rule.md) | Leave code cleaner than you found it |4243## The Boy Scout Rule4445> "Leave the campground cleaner than you found it."4647Every time you touch code, make it a little better. Small, incremental improvements compound over time.4849## Code Quality Checklist5051Before committing code, verify:5253- [ ] **Names** - Are all names intention-revealing?54- [ ] **Functions** - Is each function doing exactly one thing?55- [ ] **Comments** - Are comments explaining why, not what?56- [ ] **DRY** - Is there any duplicated logic?57- [ ] **SOLID** - Are principles being followed?58- [ ] **Tests** - Is the code tested and testable?59- [ ] **Error Handling** - Are errors handled gracefully?6061## Language Translation Notes6263Examples use generic pseudocode. Adapt to your language:64- **PHP**: `class`, `function`, `->`, type hints65- **JavaScript/TypeScript**: `class`, arrow functions, `.`66- **Python**: `class`, `def`, `.`, type hints67- **Java/C#**: Direct mapping with access modifiers6869---7071*Based on concepts from "Clean Code: A Handbook of Agile Software Craftsmanship" by Robert C. Martin, 2008.*7273---74> Converted and distributed by [TomeVault](https://tomevault.io/claim/grndlvl) — claim your Tome and manage your conversions.75<!-- tomevault:4.0:skill_md:2026-04-11 -->