- Code is communication (to the next reader)
- Boy Scout Rule: Leave the campground cleaner than you found it
- Intention-revealing names: Names should express intent
- Avoid disinformation: Avoid type information, reserved words
- Make meaningful distinctions: Avoid meaningless number sequences
- Use searchable names: Avoid single letters and magic numbers
- Class names: Nouns or noun phrases
- Method names: Verbs or verb phrases
- One word per concept: Consistent terminology
- Small: Functions should do one thing
- Single Responsibility Principle (SRP)
- One abstraction level per function
- Use descriptive names
- Function arguments: Ideal is 0, then 1, then 2, avoid 3+
- No side effects: Functions should only do what they promise
- Command Query Separation
- Use exceptions rather than return codes
- Don't Repeat Yourself (DRY)
- Comments cannot clean up bad code
- Express intent in code, not comments
- Good comments: Legal info, intent explanation, TODOs, warnings
- Bad comments: Mumbling, redundant comments, misleading comments, mandative comments, journal comments
- Vertical formatting: Related concepts close, unrelated separated
- Vertical distance: Variable declarations close to usage
- Horizontal formatting: Proper indentation, reasonable line length
- Data abstraction: Hide implementation details
- Law of Demeter: Modules should not know internals of objects they manipulate
- Data Transfer Objects (DTO)
- Use exceptions rather than return codes
- Write Try-Catch-Finally first
- Use unchecked exceptions
- Provide context with exceptions
- Define exception classes based on caller's needs
- Maintain clear boundaries when using third-party code
- Learning tests: Understand third-party library behavior
- Use Adapter pattern to encapsulate boundaries
- TDD Three Laws
- Keep tests clean
- One assertion per concept
- FIRST principles: Fast, Independent, Repeatable, Self-Validating, Timely
- Class organization: Constants, variables, public functions, private utilities
- Classes should be small: Single Responsibility Principle
- Cohesion: Each variable should be used by each method
- Isolate modification: Open/Closed Principle (OCP), Dependency Inversion Principle (DIP)
- Comments: Inappropriate information, obsolete comments, redundant comments
- Functions: Too many arguments, output arguments, flag arguments
- General issues: Deep nesting, tight coupling, feature envy, selector parameters, obscure intent