Since we’ve established that code review is an essential part of high-quality software development, a strategy is needed to ensure the success of this process. The foundation should be collaboration, open communication and knowledge-sharing between teammates. Having an established method for the reviews ensures that they are effective, they help everyone stay on track and decrease technical debt.
From a developer’s perspective, here are the key elements to consider:
Check your work before submitting it for review
You should always treat your code as a piece of art, continually striving to submit our best work. Although this does not mean obsessing over cleaning every code line, you should take care of the more global things (i.e., code style and variable names) before asking someone else to take a look. Also, make sure that you adhere to your team’s coding standards. You can leverage a static code analysis tool to help with this.
It is also important to provide context around the code you have written and don’t assume the reviewer will inherently understand the functionality of our code. This is particularly true if you worked on a brand new feature all by yourself. Since you only know the code inside out, providing context upfront will help avoid potential misunderstandings.
Finally, remember to test your code before you submit it. If your app has a fully automated Continuous Integration (CI) pipeline, leverage that to test your code. If not, thoroughly test it locally and make sure it’s functional.
Keep it concise
Try to submit short code reviews. Humans generally cannot process a lot of information in a brief period very well. When you submit lengthy code reviews, the reviewer will tend to skip over your code’s core functionality and logic. They can become overwhelmed with a large amount of information and will most likely spend less time reviewing your code.
If you are working on a significant enhancement or feature, you should submit your code review in smaller chunks. This will help you get meaningful feedback earlier in your development cycle.
Don’t take the feedback personally
We are incredibly passionate individuals when it comes to writing code. This passion helps us remain motivated to produce good quality software. Yet, the same feelings give us a false sense of ego, sometimes hurting our career advancement.
Don’t take any of the code review comments personally. Remember, the reviewer takes time from their busy schedules to provide you feedback, so take it constructively. Code reviews provide an excellent opportunity to teach and learn.
On the other hand, from a reviewer’s perspective, a code review should start with a desire to educate and not criticize the author’s work, therefore fostering a positive code review culture. Code review tasks are time-consuming and, at times, tedious, but it brings enormous benefits in the long run.
As a reviewer, these are the most important elements to take into account:
Give constructive feedback
Always provide valuable feedback to the author designed to help drive meaningful discussions. Explaining your point of view will encourage the author to present his perspective, creating a great learning experience.
Code reviews are not only for pointing out areas for improvement. They are also meant for giving kudos to the author when they have done a great job. So, don’t forget to give praise when it is deserved and the code is good.
Be conscious of tone
It is generally better to adopt a more neutral language and address the code, not the author. Instead of providing feedback like “What were you thinking?” or “What you’ve done here is incorrect”, say things like “Could we try?”, “What do you think about?”, “What happens when?”, approaching it with a friendly tone and a positive attitude. Being polite will lead to a conversation instead of defensiveness or, even worse, silence and resentment.
You can also take into account providing links to additional materials with in-depth explanations of a problem. Finally, when the process is finished, indicate if you expect the author to respond to your comments and whether you would like to check the CR after the newly implemented changes.
Learn together
Code reviews provide an excellent opportunity to collaborate. Embrace this idea. Reviewing code makes you not only a better programmer but also a great mentor. You may understand concepts even better when you teach them to someone else.
Everyone in your project team should do the code review, not exclusively the senior developers because participating in this process encourages all developers to learn a lot faster.
As it turns out, code reviews can seem straightforward, but they aren’t always. Since they are crucial in helping teams achieve desired quality standards and add more value to a product, the big challenge resides in finding a suitable model. Remember that there rarely is a one-size-fits-all approach, so strive to find the right fit to transform code reviews into a team-building activity.