DEV Community

Cover image for Tips for Better Code Review
Karan Pratap Singh
Karan Pratap Singh

Posted on • Updated on

Tips for Better Code Review

Code reviews can be really helpful to find issues before they head out to QA and also keep our code clean and efficient but sometimes they can be frustrating for the reviewer and the reviewee.

So, here are some tips for better code reviews!

Keeping PR's small

PR should be small and easily reviewable, this decreases barrier for reviews and improves quality of review

This should help show direction and minimizes re-work. If you're looking to gather early feedback, github has Draft PR feature

Focus on code not styling

This point may seem silly but it's quite true where styling isn't enforced by the language itself (for instance Go).

If this is a frequent issue in the code reviews. Try to settle styling guidelines eon either by building your own or using an existing one and automating it with CI.

How can we improve our code

It's not about you, it's about the code. So don't take the reviews personally. Both sides i.e reviewee and the reviewer should assume best intentions.

Remember to use we and not you

Actionable feedback

As a reviewer your comment should offer actionable feedback.
We've all had that one comment on our PR at some point in our life that made us think "Okay, what the hell do I do with this?"

Hence, the feedback should be actionable and a request not command.

Don't

"This doesn't seem right

Do

"We're not sure about this approach, can you try XYZ? Here's an example or docs ..."

Who do I pick?

Picking right person for a review can be helpful. So before picking the reviewer be sure to ask your self Who has the most context about this?.

Assigning code owners can also be really helpful (more on code owners)

Positive feedback

Code reviews don't have to be only about mistakes. They can also be about positive feedback.

For example:

"This looks useful! I didn't know we can do that"

"Refactoring this was a great idea, thank you!"

Lastly, remember to always be humble. Every code review can be a chance to learn something new. Have Fun!

Top comments (2)

Collapse
 
vikrantnegi profile image
Vikrant Negi

You mentioned some good points here.

Collapse
 
karanpratapsingh profile image
Karan Pratap Singh

Thanks Vikrant!