How to make a good code review?
What is meant by code review?
Code review or code review is a process allowing a developer to give feedback on the work of another developer.
The goal of this maneuver is to improve the overall code quality and identify bugs.
The code can be reviewed:
- in pair programming, as is the case with the Extreme Programming (XP) project methodology, where two developers will review the code at the same time side by side on the same screen or remotely in a split screen
- directly by the developer doing the code review, as is the case for example when our CTO reviews the code of a less experienced developer via a Pull Request (PR) on github. If the PR is validated, the developed code will be able to join the rest of the codebase (for example on the development or production environment)
How to make a GOOD code review?
Before launching headlong into the code review, it is important to ask questions about the context of this code review: do you need to
Verify that the code to be reviewed solves a particular request, for example in the context of a Pull Request (PR) to review?
Get a quick idea of the overall quality of code produced by a development team?
Make sure you can take over the code of a former developer on the way out?
Once the purpose of the review is clear, you can start testing if the source code retrieved runs well.
Other questions that are important to anwser : does it pass Unit Tests (TU) / Automated Tests? Are there any errors in the linter, prettier (code formatter) or SonarQube (qualimetry software)?
If the code passes this first step, you can test its operation to make sure that what has been implemented does what has been specified, in compliance with any designed models, and for computers but also on tablets and telephones. mobile... in the context of front-end developments, you have to make sure that the responsive has been implemented :)
Does it work in test environment? Great, you will be able to do a first pass on the code to get a first impression on the quality of the source code and check its maintainability.
If you are trying to get an idea of the level of the developer whose code you are reviewing, also keep in mind the context in which the developer who submits his code to you worked: was he under pressure to favor velocity? to quality and release the product quickly instead of refactoring its code? Were there sudden changes in decisions from the product owner, CTO or client during development? Did he have to take existing code bases or create everything from scratch?
If you are limited by time and at this stage you already have the first remarks, you can already give your feedback to the developer by consulting him.
If you have more time, you will be able to go deeper into the code and go through it with a fine-tooth comb to find any style errors, potential bugs but also the improvements to be made to simplify the code.
Also make sure that the code you review does not introduce regressions.
If you see minor issues such as typos, you can communicate them to the developer as you go, however, if you see things that would lead to major changes, it may be good to ask the question why you wish to propose these modifications, and if they are well justified, to discuss them directly with the author of the code during a dedicated point.
When you propose things to the developer who is the author of the developments, so that he can improve his code, be kind!
It's important not to offend the developer who produced the code you're reviewing by making your comments negative!
We can absolutely raise a problem in a positive way with a turn of the type "Interesting, but have you thought of consulting our coding guidelines (coding rules) which propose to..." instead of throwing a brutal "NO , THIS DOES NOT RESPECT OUR GUIDELINES! RTFM!" 😅
In the same spirit, do not hesitate to salute the practices that have been put in place by the developer following your comments on a past code review;)
You now have the keys to doing good code reviews, don't forget, patience, pedagogy and knowledge sharing are some of the keys to having a team of developers who are happy in their work!
Need an external team to audit your code?
Our development agency Blacksmith can take care of this and help you implement good coding practices! Contact us at firstname.lastname@example.org!
Articles of the same category
What are the qualities of a good website in 2024?
19.05.23Business, Company, Tech
How do you write a brief for a website?
JAMStack versus MERN Stack