Clean code is code that is easy to understand
and easy to change
.
Even bad code can function. But if code isn't clean, it can bring a development organization to its knees.
- Introduction
- Variables
- Use meaningful and pronounceable variable names
- Use the same vocabulary for the same type of variable
- Use searchable names (part 1)
- Use searchable names (part 2)
- Avoid nesting too deeply and return early (part 1)
- Avoid nesting too deeply and return early (part 2)
- Avoid Mental Mapping
- Don't add unneeded context
- Naming
- Comparison
- Comments
- Multiline Comment vs. Single-Line Comment
- Nonlocal Comment
- Never, Ever, Ever Comment Out Code!
- Don’t Make Comments Harder Than the Code
- Never Comment the Obvious
- Always try to explain yourself in code
- Avoid redundant comments
- Give up mandated comments
- Don't make noise
- Avoid closing brace comments
- Avoid position markers
- Avoid HTML comments
- Don't give too much information
- Explaining Unclear Code
- TODO Comments
- Use reference links for codes
- Functions
- Use default arguments instead of short circuiting or conditionals
- Function arguments (2 or fewer ideally)
- Function names should say what they do
- Functions should only be one level of abstraction
- Don't use flags as function parameters
- Avoid Side Effects
- Don't write to global functions
- Encapsulate conditionals
- Avoid negative conditionals
- Avoid conditionals
- Avoid type-checking (part 1)
- Avoid type-checking (part 2)
- Remove dead code
- Objects and Data Structures
- Classes
- SOLID
- Don’t repeat yourself (DRY)