The Importance of Code Reviews
Code reviews, also known as peer reviews or code walkthroughs, are an effective way of identifying defects and sharing knowledge. A code review takes place when a programmer engages a peer to review their work, in much the same way a peer might review a report before it is submitted to management. This article will highlight why code reviews are so important, the benefits they provide, and tips for completing a successful code review.
Code reviews are most effective during the development stage, since resolving defects or improving design at this stage will cost significantly less than those resolved during testing or after a production release. That is without taking into account business frustration, loss of confidence in solution, or elapsed time for production releases.
Reducing defects and costs are only two of the benefits realised by implementing code reviews. Other benefits include:
- Spreading knowledge. Code reviews provide cross skilling opportunities which enhance the overall support capability of the team.
- Providing learning opportunities. Code being reviewed includes great code and code with the potential to be great. When you see great code, be sure to call it out to the team – great code is worthy of recognition.
- Improving code quality. When the programmer knows their code will be reviewed, they will instinctively write code that is cleaner, well documented, and easy to follow.
- Helping new programmers. New programmers need support and guidance. Code reviews help new programmers and will put them on the fast track to becoming a great programmer.
During a code review, it is not efficient to just read the code, line by line, from beginning to end. There are a number of tasks, tools, and techniques that you can use to complete a successful code review. These include:
- Programmer walkthrough. This gives the programmer an opportunity to introduce the solution, the requirements, and discuss the implementation. The reviewer is able to ask questions and gain valuable insights before they look at the code.
- Try building the solution. Start by getting the latest code and compiling. It should always build, and if not, it should include build instructions.
- Check the coding standards. Code which does not follow the coding standards is not ready for review.
- Check the code quality. Tools such as ReSharper, Code Analysis, and Code Metrics are useful here and can quickly identify regions which need closer inspection.
- Review the code. Start reading the code line by line. You will not have time to read it all, so focus on the core functionality or sections with high complexity.
- Provide constructive feedback. The idea not to criticise the code, but to work together to build the best solution possible. Finding defects and considering improvements are the rewards of a successful code review.
Code which is reviewed will result in a solution that has fewer defects, meets business requirements, and is well understood and supported by the team. It is undeniably correct that code reviews are an essential part of the coding process, and that code reviews will bring your team closer to achieving operational excellence.
The post The Importance of Code Reviews appeared first on Jason Taylor.