What Is Code Review And Its Objective?
Code reviewing is a practice where the source code is broken into small pieces, which are inspected by the supervisors or seniors in the team to be carried out just before testing. It is a process mostly followed in Agile methodology.
The main objective of code review is to detect mistakes, catch early bugs and ensure that the code follows the standard practices. It can be termed as a two-way communication where both the coder as well as the person who reviews the code learns from one another and remove any potential mistakes which may later impact the product.
Working in an Agile environment, you may often underestimate the significance of code reviewing process. You may think code reviewing is going to be time-consuming, especially when you are running short on deadlines. However, this is where it becomes all the more important. The sooner you review the code and eliminate any blocker or bug possibility for later, the sooner you are able to deliver the product as per the release process. Finding bugs later in the release cycle or post migration into production would rather turn out to be more expensive and time-consuming. This is why organizations are now following a modern methodology of Shift-Left Testing where you incorporate testing right from the client’s requirement gathering phase.
Why Code Reviewing Is Inevitable?
If you believe code reviewing isn’t required as long as you are testing then the below-mentioned benefits may sway your mind towards thinking differently.
Early Bug Detection: When bugs are detected at a very early stage in the development phase, it reduces a lot of time during the testing phase. The overall process becomes a lot inexpensive. Although nowadays, automation testing reduces the testing effort and time spent, still, there is no better gift than the human nature of detecting and correcting mistakes committed by others.
Mentoring Juniors: When a fresher joins a project, seniors may not have much time to mentor or guide the junior about the coding practices or train them about how they do their job. The ideal solution in that scenario for a senior developer is to spend at least 20-30 minutes in reviewing the code written by the junior. Regular feedback will allow the fresher to develop his/her skill in coding.
Age of Agile: Nowadays most organizations follow Agile methodology and require to deliver quality work in time. Code review will enable the organization to develop a quality prototype, free from defects and developed following the standard protocols.
Team Cohesion: Frequent review discussion brings the team closer, makes them aware of each other’s strength and weakness and saves them from getting stuck in an isolated environment.
Compliance to Standards: In the Agile age, the client often requires us to abide by a certain coding standard. However, fresher developers are not often aware of industry standard coding. Frequent reviews help to ensure that the code abides by the rules and standards that have been set by the stakeholders.
Can Code Reviewing And Testing Replace One Another?
For starters, Code reviewing and testing, both are best practices to be included in a software development life cycle. However, both are unique in their own ways and must not be confused. It would be wrong to think that you don’t need code reviewing because you have testing in your SDLC or vice-versa.
Code review involves inspecting the code which may or may not include checking for bugs. It involves checking whether the style of code is under compliance by all policies, whether there is any breach of security and most importantly, whether the code can be understood easily or not. The goal is to check whether the code is simple, follows all policies and standards and most importantly, serves its purpose.
Testing, on the other hand, has several categories. The main objective of testing is not to check the code, but to check whether the application works perfectly or not. Testing involves detecting whether there are any bugs in different layers of the application, whether the application satisfies all the requirements of the stakeholders and ensuring that the issues detected are communicated to the concerned team.
Hypothetically, code review can replace testing. In case of a very small application, if more than multiple reviewers carefully go through the code, they may identify the sections that may raise a defect when unit testing is carried out. Only hypothetically, not realistically.
Testing, either manual or automation often follows a fixed approach to check the application flow and find out whether anything is behaving like the way it is not supposed to.
Code review, however, requires manual intervention. The human mind is complicated and may think of scenarios which may not have been pre-programmed while writing a test script. An experienced code reviewer can detect any line of faulty code that may cause breakage at a certain scenario which the tester may not have thought of while writing effective test cases.
However, code review can only replace testing when the application is very small and consists maybe, only a hundred line of codes. In case of a large application, the scope gets larger and no matter how many reviewers work together in inspecting the code, the application may cause breakage when the codes are integrated. That is where testing comes into play.
Testing can, however, never replace code review, either hypothetically or realistically. Although testing may detect all the bugs and get them fixed by the developers, let’s discuss a scenario which will make it clear why it cannot replace code review.
I’ll share my personal experience. Our team was working on a large dynamic web application. After the final testing phase, the entire application was satisfying every user requirements. However, there was one problem – the loading time. Even in the fastest network connectivity, the application took 4-5 seconds to load. By going through a code review phase, we found out that the CSS and scripts were a lot complex and they can be minimized by a few hundred lines. Doing so, we reduced the loading time to 2 seconds. Thus, it can be concluded that realistically, both code reviewing and testing are integral parts of a software development phase and can never fully replace each other.