Code reviews are crucial to nurturing quality code. And just as thereâs such a thing as bad code, thereâs also such a thing as bad code reviews.
So how do you perform code reviews such that they better your teamâs codebase, productivity, and overall happiness?
Today, weâll talk about 6 code review best practices to consider when reviewing someone elseâs code. As you learn how to better support your team members through code reviews, youâll also learn transferable skills that can help you advance to a future role in leadership.
Weâll cover:
Try one of our 300+ courses and learning paths: Become an Effective Software Engineering Manager.
You canât do an effective code review if youâre rushing through too many lines of code. Quality is certainly more important than quantity when youâre reviewing lines of code. If you spend too much time reviewing code in one sitting, your review will become less effective and less attentive (which defeats the purpose of getting a fresh pair of eyes during code review).
How you manage your review time may depend on your situation, but some general guidance is:
The type of feedback you provide is crucial in building rapport with your team. You should make the effort to ensure that your feedback is helpful and comes from a well-intentioned place.
Constructive feedback will help a code author get closer to merging their source code. This doesnât mean you should be solving or fixing their code for them. But your feedback should point them in the right direction, rather than toward a void of confusion.
An example of how not to give feedback: âThis code is wrong. Why did you do this?â
Always explain the âwhyâ behind your feedback. If you suggest an alternative line of code, youâd be depriving the code author from a learning opportunity if you didnât explain why it might improve their original code. Explaining the âwhyâ also reduces the need for follow-ups, by giving the author the necessary context to incorporate your feedback.
Even if you think you can cover all the bases, checklists can help streamline your code review and focus your priorities on what matters most. You could have a personal code review checklist, but ideally, youâll have a code review checklist thatâs followed consistently across the development team.
A code review checklist might contain the following considerations for the new code:
Code reviews would be unnecessarily tedious without code review tools.
Some popular code review tools are GitHub, GitLab, BitBucket, and Gerrit â but there are many others as well. Each tool has different features, but ultimately, they can all serve to streamline code reviews and easily integrate them into your teamâs software development workflow.
Try one of our 300+ courses and learning paths: Become an Effective Software Engineering Manager.
There are times where perfectionism is the enemy of good code. Sometimes youâll need to sacrifice perfectionism in order to be a team player. Your focus when reviewing code changes should be that they follow your companyâs coding standards and general coding best practices.
Unless it affects the functionality of the code or opposes your companyâs code style guide, youâll want to refrain from getting too nitpicky about trivial concerns (such as declaring variables in a certain order). If nitpicky changes are what you find yourself tripping up on, perhaps your team really has a need for more coding standards or automated tools (such as code style enforcement in your CI).
Instead of providing explicit suggestions for improvements, itâs helpful to ask open-ended questions on a piece of code. Open-ended questions invite the author to think critically and independently about their code. This can set the stage for discussion, knowledge sharing, and mentorship.
You might learn something new by asking open-ended questions, rather than assuming you know the context behind the authorâs code. Some developers think that code reviews are only a learning for junior developers â but even the most seasoned developers can learn from a beginner in the field.
Peer code reviews are an essential part of the software development process to help keep our code quality in check. We donât realistically have time to write perfect code when weâre aiming to ship new features. Even if we did, nobodyâs perfect, and thereâs always potential for mistakes.
Not only are peer code reviews a great way to great opportunities to ensure high-quality code, they also foster a positive culture of collaboration with your team.
The benefits of code reviews are numerous, some of which include:
If youâve made it this far, pat yourself on the back! Not everyone is so deeply invested in supporting their companyâs codebase health and their teamâs productivity.
If you care about doing a better code review, you truly care about the success of your team. Even if you donât plan for it yet, your interest in supporting your teamâs productivity means you also have the potential to be a great leader.
To help you go from being a team player to a team leader, weâve created the course Become an Effective Software Engineering Manager. This course covers the essentials of impactful engineering management, including how to motivate your team, manage projects, and delegate tasks effectively.
Happy learning!
Free Resources