What is Clean Code
Readable and maintainable code
Clean Code — Readable and Maintainable Code
Clean Code is an approach to writing code that is easy to read, understand, and maintain. The concept was popularized by Robert Martin (Uncle Bob).
Clean Code Principles
| Principle | Description | |-----------|-------------| | Meaningful names | Variables and functions speak for themselves | | Small functions | One function — one task | | No comments | Code is so clear comments aren't needed | | DRY | Don't Repeat Yourself — no duplication | | KISS | Keep It Simple, Stupid — simplicity |
Naming Rules
- Classes — nouns (User, OrderService)
- Methods — verbs (getUser, calculateTotal)
- Booleans — is/has/can (isActive, hasAccess)
- Constants — UPPER_SNAKE_CASE
Clean Code Characteristics
- Reads like prose
- Easy to test
- Minimal dependencies
- Handles errors gracefully
- Follows team standards
Recommended Books
- "Clean Code" — Robert C. Martin
- "Refactoring" — Martin Fowler
- "The Pragmatic Programmer" — Hunt & Thomas