Categories
code review General

Things I do before a code review

If you have contributed to an open source project, you probably know what a code review is. Github is a great platform to experience code reviews. By default, only project owners have write permissions. For collaborators, the first thing they have to do is fork a project. Once they have their own project with write permissions, they can add new features or fix a bug. When the code is ready for a code review, a pull request is created to start the review process.

In this post, I want to share what I do before submitting my code for a code review.

1 Test my own code

By default, software developers are not good testers. We put our energy and effort on writing code and verifying that requirements get met. But when it comes to code reviews, it is important that your code works as expected. Go thru all the pages you have modified and test them. Try to break your own code. For example, if you have an input that takes only numbers, try to enter strings or add more than 5 decimal places.

2 Clean up

Before I submit my code for a formal review, I pay special attention to comments. Sometimes comments do not reflect what the code is currently doing. If this is the case, I update the comments or remove them entirely.

Another area that I like to clean up is the using statements at the top. If you no longer use a library, it is a good idea to remove it. If you do remove something, make sure to rebuild your projects.

3 Make code more readable

Have you seen code without blank lines in it? I see it all the time. For example, a Javascript function made up of 20 lines but there is no blank lines in it. This makes it very difficult to read it. For the sake of everyone in your team, add blank lines to help code reviewers read the code.

4 Verify unit tests

After you go thru the clean up process, I recompile and run all unit tests. We have a Jenkins server that handles our continuous integration. As part of that build process, all unit tests are run. The last thing you want to do is submit your code for a peer review when unit tests are not passing.

Summary

If you are not using code reviews before your code gets into production, you are doing a big mistake. Code reviews allow teams to identify bugs early on. It is more difficult to fix bugs once they make it into production. And they are also more costly. Code reviews also keep your code consistent and clean. Not all companies use code reviews but they are a great tool to keep a clean and stable code base.

Leave a Reply

Your email address will not be published. Required fields are marked *