Skip to content
Go back

Writing A Code Review

Published:

Writing a code review for a large project was something that I had never done before and was quite a scary task to take on for the first time. They are a great thing to have done for a project, and help to maintain high standards and well developed solutions.

Having just left a development team and not having had any input into the codebase for the project I was the ideal candidate to write the code review. But.. I’d never written one before and didn’t really know where to start. The first thing I did as anyone would do is Google it. What did I find? Honestly, not very much for what I wanted and needed to review. Trying to follow the idea of open-learning I decided it was time to write up what you could call my opinion on how to write a code review. It isn’t going to be a perfect fit for every requirement but hopefully it helps fill a gap that I found when trying to find out how to do it.

TL;DR

If you need to write a code review for a large project and don’t know where to start:

Understand the Project

Firstly you need to understand the project, what is it and why? What is it for, what requirements are there for this project to need to be built. Why is it being built? Understanding this context will help you understand some of the decisions which have been made.
You need to understand the technology that has been used, how has it been architected and are there are design patterns that have been followed. Knowing this will help you review the code and project against the right best practices and standards.

The project that I was reviewing was a healthcare web portal that consisted of a frontend built in Angular, a dotnet backed API and a SQL Server database. I can’t really share the detail about what it was as I don’t want to give anything away! But essentially it would allow a certain set of health care professionals see records relating to a set of patients.

How to Structure the Report

After carrying out the review you need to be able to present you findings in a concise way, otherwise what is the point of doing the review? If you can’t correctly communicate what you have found then they will never be fixed! This is the structure that I followed for the report I wrote:

  1. Introduction: Give a brief description of the project and the scope of the review you are writing. The introduction should also include a summary of the recommendations and findings. This provides a quick and easy context into the report.
  2. Methodology: Describe the approach taken to review the code, including any tools or techniques used. I broke this down into each repository that I was reviewing and what each one would be reviewed for.
  3. Findings: Present the findings of the code review, including any issues or concerns identified. This is the main body of the report and should be structured in a way that makes it easy to follow. I broke this down into sections for each repository and then further into sections for each area of the codebase. This was further broken down into each repository as per section 2.
  4. Recommendations: Provide recommendations for addressing the issues identified in the findings. This should be presented in a way that would allow the audience of the report to understand what you found, why it’s a problem and what to do about it.

How to do the Review

Now we know how to structure the report, how do we actually carry out the review? This is the part that I found some of the least information about for the overall part of it. Of course there are some very clear areas that are well documented, but some can be so opinion based that what you find online doesn’t really help.

As this project had three repositories, some things that I did were the same for all three, some however are specific to a given repository.

Repository

The first thing I did which was the same for all repositories was to review the repository itself for a few elements. During this review I made sure to look at the frameworks being used before anything else. Are they the latest version? For example, in this instance the API was using .Net 8.0, which whilst was still in long-term support at the time, .Net 9.0 was released and the latest version.

Files and Folders

Sensitive Data

Pipelines

Code quality

The next step is to review the code itself. How well is it written? Can it be easily understood? Is it maintainable? Are there any issues with the code that need to be addressed? Is it documented?

Readability

Maintainability

Adherence to Standards

Error Handling

Security

Security is an important aspect of any code review. Are there any security issues that need to be addressed? Are there any areas of the code that could be improved from a security perspective? At this point some the areas to be checked vary depending on the technology stack being used, and you must be more specific depending on the repository. Some areas are of course required regardless and should be treated as such.

Authentication and Authorisation

Backend API

These are the specific areas that I looked at for the backend API repository.

Frontend

These are the specific areas that I looked at for the frontend repository.

Testing

The next key element that I reviewed was the testing of the code in each repository. Are there tests in place? Are they well written and easy to understand? Do they cover all areas of the code? Are they run as part of the pipeline?

Test coverage is also something that I looked for. The project was utilising Azure DevOps for the build pipelines, with an additional tool called Coverlet to provide code coverage reports. This tool is fantastic for both developers and reviewers. It generates easy to read reports that show you test coverage broken down by both file and the class. Back when I ran a dev team I would always push for a 80% test coverage. Can this always be achieved? No, but having a target helps to ensure that tests are written. Sometimes it just doesn’t happen though, not every path gets tested.

Recommendations

The final section of the report was the recommendations. This is where I provided recommendations to resolve each of the findings. I broke this down into a section for each repository and made sure that each recommendation was numbered so it could easily be reference.

To help the team prioritise the recommendations to resolve I scored them against a simple scale:

Conclusion

Writing a code review was not a quick job, it took me a few days once I got into it, and honestly it took me a while to get started. I think the key issue was just not knowing where to start and I hope I’ve helped you with that if you’ve read this far!

Realistically you are going to be reading code that you have never read or written, and that’s the point. Don’t be worried if it’s taking time, there is a reason you have been chosen to do it. Take your time and break it into reasonable chunks. As a friend always said to me, “Take small bites of the elephant, you can’t do it all at once”.

My last opinion is, be consistent and thorough. Take your time and remember the point of doing it is to help build great software in a great way.


Share this post on:

Next Post
Why Write a Blog?