Computers make very fast, very accurate mistakes. That’s why we always need to review what we write. We are good at collecting the best practices. And this time we can share with your code reviews best practices that we can totally recommend for use.
Yep, here we collected the most common code review suggestions for you:
- Throw an exception when things go in the wrong direction. Empty objects are not the best tool for this. If something is exceptional you should throw an exception.
- Choose the most specific possible type. It will allow you to avoid a whole class of bugs and is the reason for choosing strongly typed language like Java.
There are a number of different places where strings come from, such as:
- query and path parameters in urls
- databases that don’t support enums
- poorly written libraries
- Prefer Optionals to nulls.
Optionalallows you to completely remove NPEs from your program.
- Avoid using container objects like Optional, List, or Task as method parameters. It’s not very good when the return type is the same kind of container.
Want to know more? Check this great material.
To add some value, you can also explore our previous material about code reviews. Take care!