Write code that humans can read, maintain, and extend — not just code that works.
Clean code principles:
Naming:
- Use meaningful, intention-revealing names
- Avoid abbreviations (userId not uid, calculateTotal not calcTot)
- Names should say WHAT, not HOW
Functions:
- Do one thing, do it well
- Short (under 20 lines as a guide)
- No side effects (pure functions where possible)
- Prefer 0-2 arguments
- Command-Query Separation (function either does something OR returns something)
DRY (Don't Repeat Yourself):
- Every piece of knowledge should have a single authoritative representation
- But: duplication is better than the wrong abstraction
SOLID Principles:
- S: Single Responsibility — class has one reason to change
- O: Open/Closed — open for extension, closed for modification
- L: Liskov Substitution — subtypes must be substitutable for their base type
- I: Interface Segregation — clients shouldn't depend on methods they don't use
- D: Dependency Inversion — depend on abstractions, not concretions
Code Smells:
- Long method, large class, feature envy, data clumps, primitive obsession
- Shotgun surgery, divergent change, parallel inheritance hierarchies
Books:
- Clean Code by Robert C. Martin
- The Pragmatic Programmer by Hunt & Thomas
- Refactoring by Martin Fowler
Naming:
- Use meaningful, intention-revealing names
- Avoid abbreviations (userId not uid, calculateTotal not calcTot)
- Names should say WHAT, not HOW
Functions:
- Do one thing, do it well
- Short (under 20 lines as a guide)
- No side effects (pure functions where possible)
- Prefer 0-2 arguments
- Command-Query Separation (function either does something OR returns something)
DRY (Don't Repeat Yourself):
- Every piece of knowledge should have a single authoritative representation
- But: duplication is better than the wrong abstraction
SOLID Principles:
- S: Single Responsibility — class has one reason to change
- O: Open/Closed — open for extension, closed for modification
- L: Liskov Substitution — subtypes must be substitutable for their base type
- I: Interface Segregation — clients shouldn't depend on methods they don't use
- D: Dependency Inversion — depend on abstractions, not concretions
Code Smells:
- Long method, large class, feature envy, data clumps, primitive obsession
- Shotgun surgery, divergent change, parallel inheritance hierarchies
Books:
- Clean Code by Robert C. Martin
- The Pragmatic Programmer by Hunt & Thomas
- Refactoring by Martin Fowler