Clean Code Principles
Practical principles for writing code that is readable, testable and easy to maintain.
On this page
Clean Code Principles
Clean code makes intent obvious to the next developer, including your future self. The goal is not the fewest lines: it is code that a teammate can confidently understand and change.
Use descriptive names
Prefer a name that communicates meaning over a short abbreviation. For example, activeUsers is clearer than au.
Keep functions focused
Give functions one coherent responsibility. Split a function when its steps have separate reasons to change.
Make errors explicit
Validate inputs at boundaries and return useful error messages. Do not silently ignore failures.
Write tests for behavior
Test observable outcomes and edge cases. A test should explain what the code promises, not mirror every implementation detail.
Refactor in small steps
Improve names and structure while tests remain green. Small changes are easier to review and revert.
Checklist
- Can a reader understand the main purpose without comments?
- Do errors produce predictable results?
- Are repeated rules expressed in one place?
- Are tests readable and independent?
Clean code is a continuous habit, not a one-time cleanup.