I want to tell you about the most important process we have in our team: Peer Code Review.
Code review is not just a process, it's a culture thing. As developers we should be willing to do it. Even if it's not to a peer, you should be reviewing Open Source Project's code, you will learn a lot.
- It raises code quality, enforcing readibility, efficiency (through engineering) and maintanability.
- It minimizes bugs. More people looking at the same code will minimize bugs pushed to production.
- It encourages a feedback culture. All code should be reviewed, no matter what, no matter who wrote it. This helps us to grow and to create a constructive feedback culture.
- It disperses knowledge through the whole team, raising the bus factor. At least two people understand the code.
Let's get back to the purpose of this post, what rules I learned from code reviews:
This is not a rule, but a state of mind:
Don't be an ass.
Having your code reviewed.
- Don't take it personally. This is about the code, not you.
- Embrace change.
- Be proud of your code.
- Push small. Small amount of code is easier to review than big full blown modules. Help the reviewer.
- Give context and why and what. Tell people why you decided to do something and, more important, explain the context of that decission. The documenation is very important for this. Document your code, explain the purposes of the modules / classes so it's easy for everybody to understand.
- Get context from the reviewer, understand the why and the what.
- Write good commit messages. Commit messages matter. Part of our job as engineers is to take the time to write good commit messages. It's not for us, it's for the future of the project. Take time and do it the right way.
If you are the reviewer.
- Be respectful and have patience. (go and check the first rule).
- Give recommendations (think of the goal).
- Ask questions, don't make demands.
- You can make it different... but... there are many ways to do the same thing.
- This is not a "Why" session. If you need to ask why, ask for context first.
- Don't make people wait for you. Code reviews are very important, schedule time for code reviews.
- Take your time. Block at least one hour of your time to do it. This is important for the team, so take your time and do it the right way.
- Approve the Pull Request! (or not).