Why are Code reviews so important?

Somya Anand
4 min readAug 5, 2020

As I work as an R&D Engineer, I am getting accustomed to juggling my way between data science and software engineering. I can safely say that I have learnt a lot of best practices through effective code reviews. Whether it is your first code review or the 1000th, each code review helps us to grow a step further. There are tons of fantastic materials available online such as

I have summarized the whole code review process in general. I have divided this article into three sections:

  • Things to look while doing code reviews in general.
  • Some generic points to see while addressing machine learning code review requests.
  • Things that I follow to address code review comments.

While reviewing Pull requests and addressing PR review comments, I have observed a familiar pattern of comments. Some of the general things that can help with effective code reviews are mentioned are:

1. Understand the intent of code change on a broader level.

It’s really important to know the use case or intent of code. Focus on understanding the feature/product/bug etc. before jumping on the code. Look through the quick resources available for more context. It could be design docs, JIRA tickets, user stories, product manager, developer (PR owner). This practice not only helps to do a better code review but also keep us aware of the latest updates.

2. Go through a thorough reading of the code.

Once we have understood the intent of the code, it’s time to look for common mistakes that might need a second eye. Look out for potential I/O optimizations (for eg.: Check if the data layer is accessed optimally, is there a way to minimize DB interactions?) Check the scope of scalability, see if any process can be implemented as multiple parallel processes. Estimate potential memory utilization, (this comes handy when we deal with large data.) Consider using a better-optimized data structure for caching (e.g., Bloom filter instead of a map). See if the PR owner has missed any potential test case.

3. Ask questions.

Don’t hesitate in asking questions. A good question may lead to identifying some missing details or required reformating to ensure better code architecture. If not any of the above, it will help to improve reviewer’s context about the code.

4. Appreciate good code.

Whenever I see a well-written comment or a very concise code, it feels good to appreciate it. It makes me feel motivated to write such clean code. Also, I feel more confident about my code when I receive those helpful comments.

5. Check for common nits.

These are common nits which might be missed during code generation. Check for typos, exception handling, proper indentation, optimized loops, rewriting same stubs of code and hardcoded non-configurable values.

I review a fair share of machine learning model codes as part of my daily work activity. Following are some of the key things that I always look while doing machine learning particular code reviews:

  • Always look for potential data preparation and cleaning techniques.
  • Look out for codes which evaluate model quality.
  • See the way the model is being serialized and stored.
  • Check for the fine-tuned parameter, try to make it as a configurable parameter.
  • Understand any mentioned assumptions.
  • Check the sample requirements.
  • Review any potential test cases.
  • Check if the code takes data amount into consideration.

Things to keep in mind while addressing code review comments:

1. Acknowledge each comment.

Always go back and see if there is a required change that can be done. Even if you feel that the implemented method is more applicable, try to explain it politely through comments.

2. Measure relevancy/importance vs effort.

There are times when suggested refactoring requires a lot of code changes while resulting in minimal improvement. Then, give your arguments to support your decision.

3. Proactively approach code reviews.

Try addressing review comments proactively. It ensures that the reviewer will not lose the context of your code. This will make the potential changes effective and relevant, thus minimizing further iterations.

4. Appreciate feedback.

Feedbacks always comes from a good place. Don’t take it as a personal judgment, instead utilize those comments to write better code and grow together. It takes a lot of hard work to review someone’s code.

In a nutshell, I feel each code review improves my coding skill a notch better, makes me think twice, even when I am implementing even the smallest change. I think code reviews are a continuous learning process and an opportunity to grow together.

--

--

Somya Anand

Machine learning engineer@TextIQ, I am passionate about applied research and AI interpretability. I like to create things. Love for history, travel and art.