Code Review, as Explained to Complete Beginners
Imagine you’re a developer working on a project alongside your colleagues. You have a task — say, a module that gets some fancy data from a database. You make that thing work. You test it. It works one hundred percent according to the technical specifications you gave it. You mark that module as completed, but you can’t send it to production just yet. Your code needs to be reviewed.
You might not see it yet, but even if your code works perfectly fine, it may still have issues:
- It could be that the code isn’t well documented, or there aren’t enough comments for future developers to maintain the code
- Maybe the code uses coding practices that can impact the overall speed or stability of the system. For example, imagine that you brute forced a solution instead of creating something elegant, and that could end up crashing the whole system when it’s under load
- Perhaps the technical specifications of the project were incomplete, or they changed while you were working
- There could be something else going on with the project that affects your code.
You may be unaware of these factors, so someone needs to look out for you. This is what code review is for: your peers or managers make sure your code will play nicely with other parts of the project. Typically, your code will be reviewed by someone who knows the project a little better than you, and that will give you some valuable perspective.
The mechanics of code review vary from team to team: some developers use face-to-face meetings, and others post written comments. There are systems that allow folks to collaborate on code and do code review in real time. I once saw a developer review code in Google Docs, which is honestly rather extravagant. When it comes to code review, the tools aren’t as important as you might think.
What is important, though, is the quality of the comments. The aim of proper code review is not to criticize or humiliate, but to spark conversation and creativity on all sides. Here are some examples of good comments:
- What happens if this case fails, and no other cases are matched? Consider some rare cases for this function, e.g. the user has a long name or special characters in their email field.
- I see what you mean with this lookup. This lookup will work for low-load cases, but in a high-load situation, it will freeze up. Try optimizing it for 99% of the requests we get (see specs document).
- This uses a legacy library that we’ll stop supporting after 2021. Consider switching to…
- This function doesn’t check for valid data. The function will work in this particular case, but if we call it elsewhere, it will most likely fail. Consider building in data checks to make sure the data is valid.
Notice how the reviewer asks questions and makes assumptions, instead of giving direct orders.
If you are tasked with reviewing code, this too can be a very enlightening experience. Seeing how others solve their development tasks, how others think, and even what mistakes they make leads you to become a much better developer. So, whenever possible, participate in code reviews. They really make a difference in how you think as a developer.
Code review is unnecessary for small or one-man projects. If you need fast solutions that you will maintain by yourself, it makes sense to make your code legible and easy to maintain. However, if you fail to do so, you can always remake your code from scratch. So, if it’s just you and your friend working from your garage, maybe it’s too early to review each other’s code.
Want to learn more about coding and code reviews? Discover Practicum by Yandex. We teach you to code through real-world projects and code reviews.
If you’re interested in becoming a web developer, сheck out the article, “What’s inside: Web Developer Program.”
When you join the Practicum community, every sprint ends with a code review. Through 15 projects, all with real-life code reviews, you’ll get insights from professional developers to build your skills — and you’ll get used to how code reviews work, so you’ll already understand them when you enter the workplace.
At Practicum, we offer online education and mentoring to help you develop your career in tech. Beginners are welcome!