Anas Anjaria
Anas Anjaria's blog

Anas Anjaria's blog

Lessons I Learned as a Code Reviewer

Photo by Alvaro Reyes on Unsplash

Lessons I Learned as a Code Reviewer

We are human, and we can make mistakes

Anas Anjaria's photo
Anas Anjaria
·Aug 31, 2022·

4 min read

Subscribe to my newsletter and never miss my upcoming articles

We, as a programmer, are continuously building new features and shipping them to our production system to facilitate our customers.

But we are human, and we can make mistakes. As we develop new features, our implementation needs reviews by our peers.

Over time I learned a few lessons as a code reviewer, and I am happy to share them with you.

Review your code first before asking others

I used to open a pull request (PR) as soon as I completed my implementation and requested peers to review my work.

Sometimes I made some typos in variable names or added some print statements for debugging purposes. And reviewers usually point out these mistakes while reviewing code.

It taught me to review my code first before asking others for review. It ensures that it’s final from my end and there are no mistakes. This way, our team will focus mainly on reviewing the actual implementation.

Furthermore, I have learned that

the more we need to review the same code, the more we lose focus.

So if the team is investing time in pointing out my silly mistakes, they might overlook actual bugs.

No “YOU” attitude while requesting changes in pull requests

It pisses me off when somebody writes in my pull request.

why haven’t you closed the connection?

why haven’t you added a try-catch block?

I understand their intention that they are not impolite but simply raising their concerns. However, this “YOU” attitude is something that bothers me a lot.

As a rule of thumb, I decided to avoid the “YOU” attitude, and I can rephrase these remarks as follows.

As per my understanding, this code is not closing the connection 🤔

Adding emojis helps and reflects somewhat politeness.

Do you think it would be a good idea to surround this code block with a try-catch?

Raising a question reflects that it’s just an opinion, and you may disagree with me. You could justify it by answering my question.

I’m sorry. I am not able to understand this piece of code.

The use of “I” reflects that I cannot understand it. Maybe I lack some domain knowledge necessary to understand this implementation.

Please, have mercy on the code reviewers

If you are working on an extensive feature, please think twice before working on it. And split your pull requests (PRs) into smaller commits — no more than three commits per PR.

I completely lose focus if I have to review a big PR. You need to understand that this review process aims to:

  • Catch bugs and mistakes.
  • Increase the readability of the current implementation.
  • Pay close attention to unit tests and improve them if necessary. Unit tests are crucial to understanding any feature. The poor unit test makes it harder to understand the implementation and might add technical dept.

We could easily overlook all of these things by creating a huge PR.

Please have mercy on code reviewers and organize your work into smaller commits to not stress out reviewers.

Be honest and say it louder & clearly

Before reviewing any pull request (PR), I skip and skim. It gives a first impression of the implementation and how much time I need to invest in this PR.

If it makes it harder for me to understand the implementation, and if I lose focus, I say it louder and clearly by adding a general remark.

Please note that I am not impolite here.

Sorry, I am not able to understand this implementation. It’s harder for me to follow.

It is also feedback. If it's harder to understand for any members of a team, one should re-structure code or organize it into smaller commits.

Conclusion

Code reviews are crucial, in my opinion. While reviewing the code, I have the mindset that I might have to work on this feature tomorrow. If I cannot understand it now, I will not be able to understand it tomorrow.


Thanks for reading.

If you have any questions, please feel free to ask them in the comment section. I would be happy to answer them.

Originally written on medium


Want to connect?

anasanjaria.bio.link

 
Share this