The true value of having a code review culture
- 20 september, 2019
- Article - Software Best Practices
Code reviews are often seen as a waste of time. This is due to the perception that if you’re not creating code, you’re not being productive. Done right, a code review promotes greater quality software, stronger teamwork, and more inspiration for creativity.
The benefits of doing code reviews reach much further than improved code quality. For a well-functioning team of software engineers, reviewing the work of peers and applying constructive criticism is the most focused form of communication. Understanding why a code review process is necessary, knowing how to find reviewers, and responding to reviews correctly, are three core elements of an effective code review culture.
1. Understanding why a code review process is necessary:
• Code reviews are the most powerful form of sharing knowledge
Sharing knowledge helps development teams in several ways. Reviewers may have a better understanding about the various practices, standards and techniques in the code base that can help improve or consolidate changes. Frequent positive interaction presented in small amounts strengthens social bonds and builds trust between team members.
• Code is produced at a higher standard
When software engineers know their code will be reviewed by their peers, they are naturally motivated to clean up their code and keep consistency. Sharing work and inviting critical feedback creates a culture of taking healthy pride in work that passes the test first time.
• The style of code becomes consistent
There are often very different ways to write code and different solutions to the same problem. Consistency in a code base makes code easier to interpret, helps prevent bugs, and facilitates collaboration between software engineers. Most importantly, consistent code can be easily maintained, and code reviews present a natural and easy-to-operate safety net which promotes consistency.
• It helps being familiar with the project in its entirety
When a team works on a project, it’s highly unlikely that every member is working on every part of the application. Sometimes one software engineer will work exclusively on a single part of the system, while another is working on something else entirely. Code reviews help software engineers familiarise themselves with code they haven’t written, but might be asked to maintain in the future.
• Code reviews make for better estimates
As new features are added to the existing code, having an established code review culture in place increases the accuracy of estimations. Having multiple, informed inputs with context from different areas of the code base, ensures estimates are more reliable.
2. Finding reviewers
When establishing the guidelines for “who reviews who”, seniority should not be the main consideration. Having juniors review the code of experienced software engineers is a great learning experience for the reviewer. Not only does it give a great reference for design, coding style and architectural decisions, but it also shows how to apply these in the actual project the more junior reviewer is actively working on.
Senior software engineers should leverage the fact that new team members lack the context they have built up over the years. This can help push senior members of the team to think about problems differently.
Creating great software is a team effort. Whether someone is a junior or senior software engineer, it’s important to make everyone aware that their input is valued.
3. Responding to reviews
Having an established code review culture in place will ensure that communication lines are open and that everyone can handle criticism. Even so, it takes practice to become a great code reviewer. When capturing feedback on a review or commenting on a pull-request, reviewers should be focused on objectivity.
The reviewer’s job is to critically evaluate the work for understandability, suitability, quality and consistency. Where feedback is offered, it should explain any confusion, ask questions, offer recommendations and explore ideas, as opposed to being destructive or hostile. Having this process in place will ensure that reviewees aren’t offended by suggested changes, and that they take suggestions seriously even if they don’t agree.
If teams skip or avoid the review process, they are missing out on one of the shortest feedback loops in software development and an excellent growth mechanism for all team members.
Creating a code review culture is more than just the process of verifying source code. Promoting interaction and creating an atmosphere that encourages knowledge sharing is what is truly valuable. Code reviews with clear examples and objective feedback, within an atmosphere of trust, is a proven way to build better software, better teams and better engineers.