In the clean code series, I will cover Error Jandling, Testing and Clean classes in this post.
- Catch only Exceptions meant to be caught, for example, checked exceptions in Java
- Log as much information as possible when an error or exception occurs for analysis
- Null objects should not be returned, instead, return empty objects
- Code Coverage targets should be set and achieved
- TDD helps write testable code and reduce the number of issues
- Use the F.I.R.S.T rule for testing:
- The test is fast-running.
- The tests are independent of others.
- The test is repeatable in various environments.
- The test is self-validating.
- The test is timely.
- Single Responsibility
- Open for extension and closed for Modifications
- Readability: self-documenting class names, function names, and variable names