I did not plan to include this section; after all, who doesn’t already do code reviews? Turns out, a significant number of workplaces outside of my bubble. So here goes.
Somebody other than the author of the code should review every commit going into the master branch, offer feedback, and have the code revised to address it. This accomplishes a number of goals.
A large portion of the advice in this book is geared towards keeping code readable (in part because it’s a proxy for many other good properties of code). When considering readability, one needs to look at the code from a position lacking mental context. This is, after all, the position you’ll be in later, when needing to make changes or understand a bug a month or more down the road. The author themselves thus make a poor reviewer — their mental context is fresh, so they are mostly blind to readability issues. A reviewer is great for this simply because they didn’t write the code. They will serve as the first guinea pig to test the readability of your code changes on.
Knowledge sharing is an important part of having a smoothly functioning engineering organization. The lower your team’s “bus factor”, the healthier it is. People can go on vacation without feeling guilty that nobody will be able to modify their code. So do code reviews to spread the knowledge.
Ideally, get people better than yourself to review your code. They’ll make you grow by pointing out your mistakes or better ways to do the same thing. Take their comments, distill the nuggets of general advice from them, and put them on your “to consciously work on” list.
Finally, code reviews allow you to catch the kinds of style mistakes that the compiler and linter don’t help you with. Clearer names, better formatting, easier-to-read code layout, design flaws, inefficient algorithms, all this people are great at spotting, and computers are not.
When doing code reviews for others, be prepared for an energy drain. It’s tiring to read and really understand code, more tiring than writing it. So if you had to do a four page code review and feel fresh at the end of it, chances are you didn’t do a good job. That, or the author of the code is amazing.
Comments
Post a Comment