Code review !!
Code Review is an essential part of Software development.
Why do I need a code review?
- Not because my manager or tech lead does not trust my implementation.
- Because the second pair of eyes, when looking at the code at his/her own pace, has a good chance of finding a glitch in the code OR preventing me from checking in a bad code.
WHY TO CODE REVIEW?
Remember, the author trusts your judgment and is therefore asking you for your precious time to provide constructive feedback on his/her code.
When we are narrowly focussed on the implementation of a particular interface, or a processor class, we are likely to make mistakes. To avoid those mistakes from going into production, and providing a bad customer experience, we ask our peers to review our work.
When reviewing anyone’s code, at the least, I look for:
- Proper naming on methods, variables, classes. Do they make sense, do you understand the rationale without a need for comments?
- Team’s or company’s coding guidelines being followed
- Indentation.
- Long method code smells.
- Repetitions of any logic.
- Nested if loops, for loops, switch statements.
- Null checks, empty checks, date validations correct.
- Enough instrumentation and exception/error handling.
- Unit tests covering the scenarios.
- A lot of comments. This is dangerous if you need to explain your code in english. Comments bring complacency in writing clean code.
Sometimes, it is just better to get 1:1 with the code author to review the code. (sometimes, not always !! )
How to put comments:
- Do not sound your comments like instructions or commands.
- Make suggestions, and offer your rationale on why you think one way is better than the other.
- Compliment a well-written code.
- Ask questions if you are curious about a particular code piece, and label it as a question.
Note: These are basic for folks who are just starting and are in their early years of career. As people get more domain knowledge, and as they gain experience, code reviews can get more detailed.