24 Jan 2020
đ©ș How to do Code Review
As a reviewer youâre responsible for improving safety, enforcing broadly agreed upon standards and should use the opportunity to teach and learn from your colleagues.
đŻ The goal of code reviews
Code reviews have a few goals.
-
â Safety
The #1 priority in a code review is to provide a layer of safety to protect things from breaking for your users.
-
đ Enforcement of broadly agreed upon standards
In the cases where there are broadly agreed upon standards that arenât enforced by your test infrastructure we may need to enforce standards in reviews. Reviewers should never enforce standards that arenât broadly agreed upon.
-
đ§ Education and context sharing
Nobody comes to a company already knowing the stack. Code reviews provide a chance for us to learn from each other.
Authors are required to get an approval from any colleague in order to merge code, but that doesnât give reviewers a license to block reviews for just any reason.
-
â No stylistic preferences
Linters enforce style guidelines. Reviewers shouldnât push their personal preferences in a blocking code review.
-
â No blocking tips
Offering tips for how things could be improved is great, but reviewers shouldnât block PRs on nits.
-
â Block unsafe or non-standard code
Only safety issues and broadly agreed upon standards that arenât caught by the linter should block PRs.
â Safety
The most important goal of a code review is to provide a layer of safety. The top priority of a reviewer is to look for risks that may have been missed. There are many known types of risks that folks will be looking for and many unknown risks that youâll need to use your discretion to navigate.
đ Security and privacy
Any PR that introduces (or appears to introduce) a security or privacy issue should be blocked until the issue is resolved.
đ Bugs
Reviewers should be on the lookout for bugs where the product might not behave as intended by the author or could otherwise cause issues for users, integrity of our data, etc..
𧚠Traps for other engineers
If a method is called renameUser
but it actually deletes the user we could expect future engineers to get confused and will be at risk of introducing bugs.
đž System failures
Itâs not always easy to spot changes that could trigger cascading failures or instability of our systems. Reviewers should be on the lookout for how unexpected circumstances might impact the broader network.
đž Excessive costs
If a change might impact our costs in a material way needs to be prepared for. Reviewers should prevent changes that could unexpectedly increase costs.
đ Enforcement of broadly agreed upon standards
Ideally all of our code base policies should be encoded as linters and tests, but sometimes the infrastructure doesnât exist and we rely on engineers to enforce policy for broadly agreed upon standards.
Reviewers shouldnât enforce standards that arenât broadly agreed upon. If something has been posted in a widely read channel or at an all-hands it probably should be enforced.
đ§ Education and shared context
Nobody went to school for hacking on your companyâs stack. Outside of software fundamentals all of us had to learn how to make things work while on the job. Code reviews are one of the best ways for us to share knowledge and context about different ways things are done or tricks weâve figured out to get things done in better ways.
Reviewers should freely share questions they have about why things are done the way theyâre done in a review or offer insights into how things are done elsewhere.
That being said, education and context sharing isnât blocking. If as a reviewer you see something thatâs safe and aligns to broadly agreed standards but could be done in a different way you should let the author know but approve the pull request unless there are other issues.
đ Appendix A: Related Docs
- A Guide to Mindful Communication in Code Reviews by Amy Ciavolino