How to score an A in Code reviews

Harshit Sati
3 min readSep 12, 2021

Specially for python users

In simple words reviewing code is the act of consciously checking the code of another programmer, providing feedback and suggestions on how they can improve it, this can be done by a senior programmer for a junior programmer or two coworkers to keep each other’s code in check, in fact one can even review thier own code.

Photo by Elizaveta Dushechkina on Unsplash

Testing and logging:

Testing and logging have been the soul of production ready code, many techno sectors have adapted to test-driven deployments (TDD), even new fields like Data Science and DevOps are TDD.

  • Writing tests before you write code leads to a code that can perform well in every scenario. This might seem a bit redundant but it saves you from a lot of trouble in the long run, it is the way of test-driven deployments.
  • Unit tests can save you from the inconvenience to debug the code again when tested after completion of the project.
  • While adding new code to your tested code, you can rest assured that the new code is the only thing that can break your code.
  • There are many libraries that can help with testing your code eg pytest in python

Logging can help the reviewer understand where a problem is occurring, it can aid in debugging the program, hence make sure that the information being logged is relevant and concise.
There are various libraries to help you out with logging, in python you can use the logging library.

Clean and Efficient Code:

Clean and modular code can help you understand the code easily, there are various ways of checking if your code is readable before sending it off for a code review.

  • Ensure that the variable names are interpretable and follow snake_case.
  • Try to convert repeatable code into functions or establish classes.
  • See if you can use better data structures to perform efficient operations eg. sets would be one of the best data structure for a list of non repeatable numbers.
  • Check if you can shorten the calculations somewhere or use multiprocessing to optimize operations.

Documentation:

All successful open source projects have great documentations, not only open source projects but having documentations is a must for any project as it aids in understanding the code.

  • Make sure every complex function/operation has an explanation in the documentations.
  • There should not be a lot of inline comments but enough to assist in comprehending the code, they should be concise and meaningful.
  • Every function should include a doctring.
  • For python follow pep8 guidelines, you can also use the library autopep8 to automatically refactor your code.

In python you can use pylint to help score your code on a scale of 10, you should always aim for 7+/10.
Lastly, always use a linter while writing your code.

Don’t forget to 👏 if you like the content, this will encourage me to write more :)
Good Luck with the code review!

Further Reads:

--

--