Code Review

When you are developing on Task Branch, quickly moving work to the Main Line, you want to ensure quality and consistency since changes affect the entire team. Tests and other automation help and feedback from other developers on approach, style, design, and testing approach can provide useful insights. This pattern describes a way to get prompt and useful feedback from team members before you integrate changes into the Main Line.

Balancing Feedback, Learning, Speed, and Quality

Before work related to a development task in a development workspace is ready to merge into the Main Line, the developer wants to have confidence that the code is:

Some of these criteria can be addressed by automated testing and static analysis tools, but:

You can ask another developer to review the code before it’s merged as a person can provide perspectives that tools can’t, but a review by another developer adds a handoff step to the process, and handoffs can introduce delays that can significantly slow down integration into the_ Main Line._

Another option is to use a “fail fast” approach, where a developer merges code to the main line when they think it is ready, and the team places mechanisms in place to recover from errors. Having reliable rollback mechanisms is an attribute of a robust development process, and this will help improve the speed of integration but:

Feedback can sometimes be viewed as judgmental and critical rather than a collaborative attempt to improve code quality. You want to ensure that the feedback can focus on significant issues rather than minutia or matters of opinion.

Quick feedback is better, but feedback that is too cursory or not useful enough has little value. Spending more time giving feedback can lead to a point of diminishing returns, reducing the impact of the feedback that you can get from deployed code.

Any sort of review step needs to balance:

![](code-review-context-forces.png height=“1.5 in”)

You want to get the benefits of collaboration with your team to improve overall code quality while leveraging tools and automation and not injecting long delays into the integration process.

Relevant, Timely, and Actionable Feedback

** Before merging code from a Task Branch into the Main Line get feedback from another developer. Identify practices that ensure that the feedback is timely and that the reviewer has the appropriate context. Leverage automation where possible to focus on human time. Acknowledge the cost-benefit for some trivial changes where cursory reviews might be sufficient.**

![](code-review-branch-1.png height=“1.5 in”) Good Code Reviews are a form of collaboration that can:

The kind of feedback that achieves these goals is:

Relevant feedback addresses the code’s context, including requirements, design discussions, etc. General programming feedback about style and related issues is useful, but Automated Checks are often better for that feedback. The more context the reviewer has about the problem, the solution, and the design, the easier it is to be relevant.

Timely feedback is sufficiently prompt so that the developer does not lose context because of time spent waiting. Timeliness does not mean “immediate,” though sooner is often better. The definition of “timeliness” should be part of a team’s working agreements.

Actionable feedback is as specific as possible and suggests specific actions to take or questions to discuss. Vague comments about concerns or errors slow down the process.

Ideally, reviewers should be participating team members. Avoid:

A designated reviewer model and external feedback can slow down the process due to scheduling bottlenecks and less contextually informed comments.

It’s easy to get caught up in discussions about tools and the code review process itself when trying to improve it, but most of the challenges with code reviews come down to:

A good code review is about sharing knowledge and Identifying gaps that tools can’t find. It won’t be perfect, and taking longer in the name of perfection often yields worse outcomes than doing a quicker (or no) check and fixing any problems, as long as you later strive to identify what the issues were.

Code Review feedback can be delivered either interactively or asynchronously. Interactive feedback, where code is discussed in real-time, can take any number of forms:

Synchronous feedback doesn’t preclude some preliminary time to review and comment; much like preparing for a meeting, reviewing code “offline” can make for a better review, as long as the interval between the request for feedback and the start of a conversation is short.

Asynchronous Feedback is often associated with a_ Pull Request_ Process, though it can occur in other ways too. Asynchronous feedback can make sense for:

Even when feedback is asynchronous, it’s essential that it be prompt and that conversations (as opposed to self-contained comments) move quickly to an interactive forum.

Remember:

If your process requires approval before merging and feedback is asynchronous, err on the side of permissive approval (“approved pending these changes,” for example). Permissive approval avoids delays and demonstrates trust in team members.

Example

After a development task is completed, a developer posts a message to the team Slack channel asking for feedback and indicating the location of the change. (The mechanism could be a Pull Request, a Task Branch, or simply a request to meet, though it’s often useful to give people a short amount of time to read the code before gathering.)

Team members offer feedback, and the developer makes appropriate changes and then merges the code.

Other Forums

Narrowing the scope of code review is an essential part of meeting the time to integration goals. But not all review and feedback has this purpose. Some goals are better achieved in other forums:

Review Effort (and Skipping Review)

Not all code needs the same level of review; consider the risk of a change. Some changes you can identify as low risk (either via a tool or heuristic) might not need a peer review — passing automated tests and checks can be sufficient.

Metrics

If you feel like your code review process is bogging down, there are some metrics to track to help you identify bottlenecks:

Using a Pull Request mechanism makes it easier to collect this data, though it is still relevant for any feedback process.

Cautions

If the team loses track of the purpose of Code Review—collaboration—it can easily become a bureaucratic, low-value process.

In particular, avoid the following traps:

While speed is important, do not skip steps in favor of speed. If the feedback cycle is taking too long, work to improve the process.

When gathering metrics, use them for understanding rather than evaluation. If the metrics look bad, the reasons might be out of individuals’ control yet easy to fix.

Next Steps