<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Peer-Review on hereticles</title><link>https://icle.es/tags/peer-review/</link><description>Recent content in Peer-Review on hereticles</description><generator>Hugo</generator><language>en</language><lastBuildDate>Tue, 26 May 2026 10:27:16 +0100</lastBuildDate><atom:link href="https://icle.es/tags/peer-review/index.xml" rel="self" type="application/rss+xml"/><item><title>Pull/Merge Request Peer Review: Good Practices</title><link>https://icle.es/2025/01/25/pull/merge-request-peer-review-good-practices/</link><pubDate>Sat, 25 Jan 2025 13:47:53 +0000</pubDate><guid>https://icle.es/2025/01/25/pull/merge-request-peer-review-good-practices/</guid><description>&lt;p&gt;I wrote this when I was at muster.chat. It is lengthy, and it is draft.&lt;/p&gt;
&lt;p&gt;The polished version
&lt;a href="https://icle.es/files/muster-good-practice-guide.pdf"&gt;is much nicer&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The merge review process is a common part of the software development lifecycle
now, and this document covers practices that can help improve the process and
make it smoother and maybe even more enjoyable for your team.&lt;/p&gt;
&lt;h2 id="good-practices"&gt;Good Practices&lt;/h2&gt;
&lt;p&gt;This document started its life as a &amp;ldquo;Best Practices&amp;rdquo; document, but &amp;ldquo;Best
Practice&amp;rdquo; only applies within a specific idealised scenario. In reality, few, if
any teams are within this context.&lt;/p&gt;</description><content:encoded><![CDATA[<p>I wrote this when I was at muster.chat. It is lengthy, and it is draft.</p>
<p>The polished version
<a href="https://icle.es/files/muster-good-practice-guide.pdf">is much nicer</a></p>
<p>The merge review process is a common part of the software development lifecycle
now, and this document covers practices that can help improve the process and
make it smoother and maybe even more enjoyable for your team.</p>
<h2 id="good-practices">Good Practices</h2>
<p>This document started its life as a &ldquo;Best Practices&rdquo; document, but &ldquo;Best
Practice&rdquo; only applies within a specific idealised scenario. In reality, few, if
any teams are within this context.</p>
<p>Accepting the reality of life, the document is about good practices. All of the
practices here will bring benefits. Some of them will bring more benefit than
others, but by the same token, some of them are more work to implement.</p>
<p>You will have to decide how you want to take this journey of improvement of the
review process. It is far better to implement one change that is sustainable
than try to implement 5 changes that fall by the wayside in a month or two.</p>
<blockquote>
<p>Slow and steady (and deliberate) wins the race</p>
<ul>
<li>Aesop</li>
</ul>
</blockquote>
<h2 id="pullmerge-request">Pull/Merge Request</h2>
<p>These days, code reviews are usually done through <code>Pull Requests</code> (by GitHub,
Bitbucket, Gitea, etc.) or <code>Merge Requests</code> (by GitLab).</p>
<p>Pull request, as a concept makes more sense in open source software where
someone forks a repo and requests their changes to be &ldquo;pulled&rdquo; into the original
repository.</p>
<p>Within the context of a team where the requests are internal, the term merge
request is easier to understand.</p>
<p>Both the terms are generally used interchangeably.</p>
<h2 id="target-audience">Target Audience</h2>
<p>A lot of the items in this document can be valuable for review processes in all
kinds of software development teams. However, this document is primarily aimed
at teams who collaborate internally with trusted members, i.e. within an
organisation as opposed to open collaboration with strangers.</p>
<h2 id="a-little-history">A little history</h2>
<h3 id="old-school-code-reviews">Old School Code Reviews</h3>
<p>Code reviews can add a lot of value to a software engineering team. Before git,
and pull requests (or merge requests), code reviews happened differently.</p>
<p>There would be physical gatherings, and everyone gathered around a single
computer, or the code was printed out (leading to the 80 char line length limit
that we see even now).</p>
<p>There were also email based reviews, attaching the patches to emails, which the
reviewers replied to with comments or suggested changes. In some cases source
control systems were set up to automatically email people on each commit.</p>
<p>These reviews were after the fact. The code was already merged in and the
outcomes of the review were added afterwards.</p>
<h3 id="the-revolution-that-git-brought">The revolution that git brought</h3>
<p>Git brought with it lightweight branches, and along with a more ubiquitous
internet, the path was paved for pull/merge requests.</p>
<p>Gerrit, by Google provided an early implementation of a workflow where changes
could be proposed, discussed and reviewed before merging. This process was
refined and followed up by the git platforms like GitHub and GitLab soon after.</p>
<p>Reviewing code before merging it in is such a common pattern now largely due to
the great deal of value it brings. These processes have been a game changer for
open source software which gets contributions from external, often untrusted
parties.</p>
<p>Teams that only have contributions from trusted sources also implement processes
to review code before merge. These processes, however, can be tuned for much
higher velocities and is our main focus.</p>
<h3 id="the-pull-request">The Pull Request</h3>
<p>The concept of the Pull Request was invented by Linux Torvalds with the
introduction of <code>git-request-pull</code> into git.</p>
<p>The idea of it was to support pulling in changes from a forked repository.
GitHub subsequently popularised the concept.</p>
<h2 id="benefits">Benefits</h2>
<p>With a good peer review process in place, every team should be able to improve
their effectiveness, and improve the quality of their code base. These benefits
usually result in the team being able deliver better software and in a more
timely fashion, which also improves the team&rsquo;s credibility.</p>
<h3 id="improved-code-quality">Improved Code Quality</h3>
<p>Alexander Pope pointed out that &ldquo;To err is human,&rdquo; and you probably know the
proverb that &ldquo;two heads are better than one.&rdquo; Peer reviews bring the benefits of
expertise from multiple people to improve the quality of code.</p>
<p>This brings in benefits in the form of:</p>
<ul>
<li>Decreased defect rate</li>
<li>Improved Security</li>
<li>Improved maintainability</li>
</ul>
<p>Arguably, if your entire team review a bit of code, it should have all the good
qualities of code from your entire team. While impractical and with diminishing
returns, the key is however to get the right people to review code for maximum
benefit.</p>
<h3 id="improved-team-effectiveness">Improved Team Effectiveness</h3>
<p>This is by far the biggest benefit of code reviews. Each review improves the
knowledge and the capability of the team. Reviews also help to reduce the risk
of knowledge silos by encouraging knowledge sharing.</p>
<p>Working together as a team also has other benefits including improving morale,
the work culture and engendering a sense of purpose, all of which leads to
longer term employment.</p>
<h4 id="improve-team-communication--collaboration">Improve Team Communication &amp; Collaboration</h4>
<p>Good code reviews encourage team members to interact and work out how to express
their thoughts and feeling about lines of code. Apart from helping to strengthen
the relationship between the members of the team, it&rsquo;ll also improve the teams
ability to communicate with each other, making the team more effective overall
in achieving its goals.</p>
<h4 id="knowledge-sharing">Knowledge Sharing</h4>
<p>There are multiple knowledge sharing benefits. The biggest one is an improved
level of general product and code base knowledge within the team. In other
words, it helps to mitigate knowledge silos.</p>
<p>It&rsquo;s a good idea to get team members who are unfamiliar with the code in the PR
to review them. An outside perspective can often help to raise potential issues
or opportunities that were not previously considered. It would also help with
cross pollination in terms of knowledge sharing.</p>
<p>Another valuable aspect of code reviews is in the onboarding process. By
reviewing other requests, new starts get a safe space to dive into the code and
get a better understanding of how things work. A fresh perspective can also help
identify potential blind-spots and areas for improvement. On the other side,
when they ask for a review of their code, they also get early feedback, which
can help them re-align their ways of working and understanding as required.</p>
<p>Code reviews are a good way to maintain high visibility of the code base and
changes to it. This awareness and knowledge of the code base helps to reduce or
eliminate knowledge silos and improve the all around quality of the code.</p>
<h4 id="team-cohesion--resilience">Team Cohesion &amp; Resilience</h4>
<p>With both of the above, the team has better cohesion. By eliminating knowledge
silos and improving the level of knowledge of the team, the team is able
communicate better within itself, and externally. Every team member is more
likely to give the same answer to a question, and reliance on any individual to
be able to answer a specific question diminishes over time. Furthermore, a new
team member will find it easier to onboard to the team and when a member is on
vacation or leaves the team, there is less of a knowledge gap.</p>
<p>There is one other valuable aspect, and that is of alignment. The peer reviews
become a near constant form of checking in on direction. With these check-ins
the team as a whole is going to be moving together in the same direction.</p>
<h3 id="improved-team-credibility">Improved Team Credibility</h3>
<p>Improving the code quality and the team effectiveness are powerful tools to be
able to understand what the team is capable of delivering and in delivering it
effectively. This capability will inevitably improve the credibility of the team
and its ability deliver.</p>
<h2 id="challenges">Challenges</h2>
<p>Doing peer reviews of merges can also have some challenges, though they are
usually easily overcome. A team that refuses to do code reviews may have more
fundamental challenges to overcome first.</p>
<h3 id="collaboration-requirement">Collaboration Requirement</h3>
<p>Doing regular peer reviews requires a high level of team collaboration, starting
with the logistics of when and how the reviews happen. However, practicing peer
reviews usually improves team collaboration.</p>
<p>If the collaboration requirements are too high for a team, the team likely has
far larger challenges to tackle first.</p>
<h3 id="infrastructure">Infrastructure</h3>
<p>Being able to do peer reviews requires tools that support in it. Fortunately,
there are plenty of platform that support this (e.g. GitHub, GitLab, Bitbucket)
and you can even deploy your own ones (e.g. Gerrit, GitLab).</p>
<p>Getting a working setup for managing peer reviews for merges should be
negligible effort and cost as it has become a part of most development processes
today.</p>
<h2 id="misconceptions">Misconceptions</h2>
<p>There are plenty of misconceptions about the merge peer review process. Let&rsquo;s
cover some of them here. If you know of others, please let us know, and we&rsquo;ll
update it.</p>
<h3 id="it-slows-things-down">It slows things down</h3>
<p>It is easy to understand why it might seem like peer reviews can slow down
development. In a way it does: a software product that does not have peer review
<em>might</em> get delivered sooner under some rare circumstances. However, once the
most critical preventable bugs are addressed, it will likely have taken longer,
and have cost goodwill and morale.</p>
<p>Code reviews in fact speeds up development because the sooner you can find
potential problems, the easier and quicker it is to resolve.</p>
<p>This is probably the perfect time for a reminder that:</p>
<blockquote>
<p>The only way to go fast is to go well</p>
<p>&ndash; Robert C. Martin (Uncle Bob)</p>
</blockquote>
<p>The improved alignment of the team also means that even if everyone is moving a
little slower, everyone is moving in the same direction. Contrast this with a
team where everyone is moving quicker but in (slightly) different directions.</p>
<h3 id="only-senior-developers-review">Only Senior Developers Review</h3>
<p>One reason for a peer review is to improve the quality of the code. An engineer
with a lot of experience will bring value to the review. There will be issues
that they are better at identifying and helping to resolve. However, having
someone with little or no experience review code will also contribute to
improving the quality of code. Part of this is simply from having another point
of view. The more diverse the input you can get, the more valuable the review.
Each of us know different things, and have different strengths. The more people
who collaborate, the higher the quality is likely to be.</p>
<p>There are other reasons for code review including visibility and building
familiarity. There might be parts of the code that impacts others work either
now or in the future, and it&rsquo;ll make it easier for others to do their work
later. There are also opportunities to learn from code reviews, including from
junior developers who may be looking at the problem through a different lens.</p>
<h3 id="only-for-big-projects">Only for big Projects</h3>
<p>It might be true that the larger the project, the more value peer reviews can
bring. A lot of this value comes from the diversity of feedback that can be
collected. However, a small two person project also benefits from peer review.
While the diversity in perspective might be lower, having more than one
perspective is still hugely valuable.</p>
<p>Peer reviews are a great way to catch potential issues early, even in small
projects and this can have a positive effect on morale and the external
perception of the teams ability.</p>
<h3 id="pursuing-perfection">Pursuing Perfection</h3>
<p>Reviews are not about someone with more knowledge or experience imparting their
wisdom to others. It is also not an effort to get the code base perfect! There
is of course no such thing.</p>
<p>Peer reviews are about collaborating together to build something, within the
constraints of the circumstances, that is a well thought out way to solve the
given problem.</p>
<h2 id="alternatives-to-peer-review">Alternatives to Peer Review</h2>
<h3 id="pair-programming">Pair Programming</h3>
<p>Pair programming can function a little like a code review session. Due to its
nature, it can reduce the requirement for code reviews, particularly in a tiny
team. However, it is still a good idea to get code that was done in a pairing
session to go through a code review. The more diverse the perspectives you can
get, the better.</p>
<h3 id="mob-programming">Mob Programming</h3>
<p>Mob programming would effectively eliminate any requirement for code reviews
since the code is build collaboratively, with the review happening live.</p>
<h2 id="the-basics">The Basics</h2>
<blockquote>
<p>The more frequently we integrate, the less places we have to look for conflict
errors, and the more rapidly we fix conflicts.</p>
<p>&ndash; Martin Fowler</p>
</blockquote>
<p>Before git, everybody committed directly to the main branch, which was called
trunk. It was a good idea to commit (or integrate) early and often. Otherwise,
you&rsquo;d find yourself with merge conflicts.</p>
<p>The PR/MR flow is essentially the same, except that the old school commit has
become the request to merge.</p>
<h3 id="when-to-review">When to review</h3>
<p>While there is good reason to gate the review on merge, this is not always the
best method. There is no reason for it to be the only method either.</p>
<p>The review that happens at each stage has different priorities as well.</p>
<h4 id="before-writing-code">Before writing code</h4>
<p>It&rsquo;s a good idea to come up with a plan of action for how you are going to solve
the problem. You can come up with the initial solution collaboratively.
Alternatively, once you have a viable solution, run your team through it to get
additional opinions and perspectives. Course correction here is the easiest and
the lowest cost.</p>
<p>The main purpose of the review here is to ensure that the approach is sound, no
critical options or possibilities are missed, and more importantly that the
correct problem is being solved.</p>
<h4 id="draft-reviews">Draft Reviews</h4>
<p>If there is some complexity it may be worth getting some additional perspectives
once you have some tests and rough code. The draft review may also be valuable
if you are new to the team or to software engineering.</p>
<p>The review at this stage again focuses on the overall approach and ensuring that
there are no gaps in communication or understanding.</p>
<h4 id="ready-to-merge">Ready to merge</h4>
<p>Most reviews happen when a small enough bit of work is complete. This stage is
also where most reviews tend to happen.</p>
<p>The main outcome here should be to ensure that the change does not negatively
impact the code base and that it adds value.</p>
<p>The main question to be asked is:</p>
<blockquote>
<p>Is it good enough to merge</p>
</blockquote>
<p>There could be changes and fixes that are improvements that could be completed
in subsequent merges and that is to be expected.</p>
<h4 id="after-the-merge">After the merge</h4>
<p>There is no reason to ignore a review because it has been merged. The best time
to find an issue is when the code is being written. The second best time is
before it impacts the customer.</p>
<p>Once the code has been merged, there is less time pressure and the review can
happen with more rigor. Any improvements that come out of the review can be
completed in subsequent merges.</p>
<h3 id="your-motivation">Your Motivation</h3>
<p>While there are lot of benefits to the team from doing reviews, what are the
benefits to you?</p>
<h4 id="as-a-requester">As a requester</h4>
<p>Getting your code reviewed isn&rsquo;t about getting it &ldquo;checked&rdquo; or &ldquo;graded.&rdquo; It is
about a collaborative effort to try to ensure that the quality of the code is in
general as high as <em>reasonably</em> possible.</p>
<p>Part of the benefit to you is that there are likely to be fewer defects in the
code you write. Nobody wants the customer to be impacted by a bug (particularly
a critical one at the weekend), and this is one way to try and mitigate that
risk.</p>
<p>You could learn something new. No matter how long you have been writing
software, there is a good chance that you can learn something from someone else
reviewing your code. Continuous improvement applies not just to the code, but
also to our abilities.</p>
<p>It is also an opportunity to mentor the more junior members of your team.
Learning to mentor others is an important skill in becoming a better engineer.</p>
<p>Asking for someone to review your code is a privilege. There is no need to be
entirely responsible for the code you write, and to try and think about <em>all</em>
the ways in which it could do wrong. Lean on your team.</p>
<p>Encourage your team to ask questions. Perhaps you were too close to the code and
didn&rsquo;t realise that some of it isn&rsquo;t as easy to understand. You&rsquo;ll appreciate
making it easier to understand when you come back to it in six months or a year.</p>
<h4 id="as-a-reviewer">As a reviewer</h4>
<p>Depending on your level of experience and your role, there are many benefits
from reviewing code.</p>
<p>Reviewing code is undoubtedly a privilege and a valuable activity for the
reviewer. When defects are found, it impacts the whole team and usually also
impacts the customer. In a lot of cases, a code review could have picked it up
and prevented it altogether. The time spent in code reviews is paid back many
times over in the time saved hunting bugs and in the related restorative work.
It will reduce stress and effort for the future you.</p>
<p>Having a better understanding of the code base as a whole has its own benefits.
It is also an opportunity to align on tools and libraries in use.</p>
<p>There are further benefits based on your experience and role.</p>
<h5 id="junior">Junior</h5>
<p>Of all the roles, the junior developer perhaps stands to gain the most from code
reviews. It is worth taking every opportunity to do reviews. These are excellent
opportunities to see how others solve problems and to ask questions.</p>
<p>Reviews aren&rsquo;t just about making software better. It is also about making sure
that the code is easy to understand and to follow - for everyone. If you are
unsure about something, ask the question. Maybe the code needs to be simplified.</p>
<h5 id="seniorlead-developers">Senior/Lead Developers</h5>
<p>The biggest advantage for senior/lead developers is the opportunity to check
that the code being written is in line with your expectations and direction.
Reviews are the most valuable opportunities to ensure this.</p>
<p>Unless you are in a small team, it would make sense to focus on the big picture
and on mentoring the more junior members of the team to pick up the smaller
details in the review.</p>
<p>Your experience will help you pick up potential issues that others may miss, and
it is critical to flag these. In identifying these at this stage instead of in
production, you are saving yourself a great deal of pain in the future.</p>
<h5 id="quality-assuranceproduct-ownerscrum-master">Quality Assurance/Product Owner/Scrum Master</h5>
<p>If you use Behaviour Driven Development (BDD)—and you probably should—it would
make sense for the whole team to do some code reviews including the Product
Owner. This opportunity is really valuable for the PO and anyone in Quality
Assurance to close any gaps in understanding of what the code should be doing.</p>
<p>If you are not using BDD, it is still a good idea to try and make the tests,
particularly the functional ones as easy to understand as possible. Peer review
is an opportunity for the whole team to check their alignment. The better you
are able to make use of it, the more value it will bring.</p>
<h3 id="empathy--compassion">Empathy &amp; Compassion</h3>
<p>Peer reviews are a social and collaborative activity. It is important that you
bear this in mind when doing reviews. No matter what the issue or disagreement,
put the people first. It is more important that you collaborate to a reasonable
solution than getting the code into some &ldquo;perfect state.&rdquo;</p>
<p>Remember, that one of the purposes of code reviews is for the whole team to pull
in the same direction. Explain, clarify and discuss solutions and alternative
ways of doing something. Ultimately, any action should be agreed together as a
team as much as possible.</p>
<p>The priorities in communication should be:</p>
<ul>
<li>Kindness &amp; Compassion: It is difficult to know what others are thinking, or
what they are going through. No matter how you feel about someones work,
express it with kindness and compassion.</li>
<li>Polite: No matter who you are or who the other team member is, it is important
to be polite. Being rude damages credibility and team cohesion.</li>
<li>Respect: Another valuable trait in any team member, the absence of which
results in losing credibility, team cohesion and morale.</li>
<li>Direct Communication: Talk about the code, not the person, and about how it
could be improved. Avoid value judgments and make your statements as objective
as possible.</li>
<li>Humility: The aim is to improve the quality of the code. No matter who found
an issue or how embarrassing it might seem, it is more important to improve
the code. Appreciate the input so that they are motivated to find issues for
you next time. Remember that it&rsquo;s better to find the issue now than in
production.</li>
</ul>
<p>In other words, consider the team and its members to be the most valuable, and
through a better understanding of each other and collaboration, aim to achieve
the outcome of improved code.</p>
<h2 id="the-review">The Review</h2>
<p>The review is a whole team process and starts long before the request comes in.</p>
<h3 id="as-the-team">As the team</h3>
<h4 id="be-holistic">Be holistic</h4>
<p>As humans, we are prone to bias, errors, and unverified claims. Peer reviews can
provide differing views which serve to question and dispel at least some of
these and helps to improve rigor, credibility, and diverse perspectives. These
benefits can go beyond code.</p>
<p>The more holistically you can consider your reviews, the more value you can get
out of it. Consider the impact of code everywhere, not just in that context that
it was built. How does it impact:</p>
<ul>
<li>Infrastructure</li>
<li>Costs</li>
<li>Customer / User</li>
<li>Support &amp; Maintenance</li>
<li>Marketing</li>
<li>Other areas of the business</li>
</ul>
<p>How can you ensure that code review takes all the relevant areas into
consideration? What else could benefit from review?</p>
<p>Defining and continually improving processes that support this is important.</p>
<h4 id="processes">Processes</h4>
<p>If you don&rsquo;t already have an agreed set of guidelines and expectations, you
should work towards getting that in place. These guidelines should include:</p>
<ul>
<li>Coding standards (use pre-existing ones if at all possible)
<ul>
<li>Branch naming (and validation)</li>
<li>Rules for TODO&rsquo;s and other tags (and checking)</li>
<li>PR naming strategy
<ul>
<li>It is a good idea to treat the PR title as the merge commit title</li>
</ul>
</li>
<li>Git guidelines
<ul>
<li>Conventional commits?</li>
<li>How much to curate and fixup commits (or whether to squash)</li>
</ul>
</li>
</ul>
</li>
<li>Architectural Safeguards
<ul>
<li>Modular Components to minimise merge conflicts</li>
</ul>
</li>
<li>Knowledge Sharing
<ul>
<li>How will you avoid single person dependencies for code reviews?</li>
<li>How will you mitigate knowledge silos?</li>
</ul>
</li>
<li>Review Process
<ul>
<li>When is a PR in draft state, and when is it ready?</li>
<li>How should branch protection work?</li>
<li>Target time until first review?</li>
<li>Target time to merge per PR?</li>
<li>What&rsquo;s the maximum size of a PR? (recommendations later)</li>
<li>What constitutes a request for change instead of approval? i.e. what blocks
a merge?</li>
<li>When do you request a re-review?</li>
<li>What kind of changes can happen in a subsequent PR? (How) do you track those
requests?</li>
<li>Who commits? Merge, Squash or Rebase
<ul>
<li>It usually makes sense for the requester to do the merge, at the very
least as a way for them to close off the work they have completed.</li>
</ul>
</li>
</ul>
</li>
<li>Review templates</li>
<li>Who does reviews? How many reviews are required?</li>
<li>Communication
<ul>
<li>Who needs to be included</li>
<li>What areas of impact needs to be considered?</li>
</ul>
</li>
<li>Ownership
<ul>
<li>Which team is responsible for which parts of the code (set up CODEOWNERS)</li>
</ul>
</li>
</ul>
<h4 id="automation">Automation</h4>
<p>Once you have agreed as much of the processes as possible, the next step is to
automate as much of those as possible. For instance:</p>
<ul>
<li>Validate:
<ul>
<li>Branch names</li>
<li>Commit messages</li>
<li>Size of PR</li>
</ul>
</li>
<li>Configure review rules:
<ul>
<li>Branch protection rules</li>
<li>Minimum Reviewers</li>
</ul>
</li>
<li>Run linters (configured with your coding style)</li>
<li>Configure auto-detection of common errors:
<ul>
<li>Stray print statements</li>
<li>Newline at end of file</li>
<li>Spaces at end of line</li>
</ul>
</li>
<li>If possible/relevant, assign reviewers</li>
<li>Build &amp; Run all tests</li>
<li>Deploy a test instance</li>
<li>Static Code analysis</li>
<li>Scan for dependency updates</li>
<li>Scan for security vulnerabilities</li>
</ul>
<p>Automating these will make it pull requests quicker and allow their reviewers to
focus on the more important issues. It also means that the requester can
&ldquo;self-serve&rdquo; to improve quality themselves.</p>
<h4 id="collect-metrics">Collect Metrics</h4>
<p>The next part, which is also important is often ignored in development teams.
Collecting the metrics of your development process is at least as important as
all the metrics you collect from running systems.</p>
<p>The metrics you collect can help you identify process issues, improve, and to
measure progress.</p>
<p>Some of the valuable metrics you can collect are:</p>
<ul>
<li>Size of PR (lines of code)</li>
<li>Time to first review</li>
<li>Reviews per PR</li>
<li>Cycle time (time from PR creation to merge)</li>
<li>Defects (and seriousness)</li>
</ul>
<h4 id="continuous-improvement">Continuous Improvement</h4>
<p>Another key part that should be done as a team is continuous improvement. Having
an intention to monitor and continuously improve the process is a key part of
agile, and is no different when it comes to peer review.</p>
<p>The metrics you collect (from the above section) should help with this.</p>
<p>Metrics aren&rsquo;t everything though - you could bring cycle time down to zero by
not doing a review but that will almost certainly increase defects.</p>
<h2 id="as-the-requester">As the Requester</h2>
<p>As the one requesting a review, the largest burden of the process falls on you.
The goal is to get high quality reviews from a reasonable number of relevant
people.</p>
<p>To achieve this, you want to make the review as easy as possible for the
reviewers. One important aspect of the process is making sure the feature you
are building is the feature that was asked for. The second part of this is
validating that you are building it the way it is expected.</p>
<p>Only once alignment has been confirmed can we move on to general code quality,
bug finding, maintainability, and the other benefits that the review brings.</p>
<h3 id="break-it-down">Break it down</h3>
<p>Before you start on your feature, it&rsquo;s worth thinking about how you are going to
split it into PR&rsquo;s. Unless it&rsquo;s a tiny feature, you will likely want to do
multiple self contained small PR&rsquo;s to complete the feature.</p>
<p>If the implementation of the feature is nontrivial, another thing you might want
to do before you start is to work out a rough plan of how you are going to
implement it, ideally collaboratively with the team.</p>
<p>This can help validate alignment, both on what your going to implement and how.</p>
<p>Each subsequent PR is an opportunity for further validation. If you need course
correction, the earlier it is flagged, the easier it is.</p>
<h3 id="prep-while-you-work">Prep while you work</h3>
<p>While you are building the feature, it&rsquo;s worth thinking about what will go in
the PR description:</p>
<ul>
<li>What specific part of the feature is getting implemented?</li>
<li>What screenshots would represent the functionality?</li>
<li>Are there screen recordings that could help the reviewer understand the
functionality?</li>
<li>What&rsquo;s the impact of this specific change?</li>
<li>Are there any risks?</li>
<li>What should the reviewer test? How?</li>
</ul>
<p>It may help to start collecting some of this into a draft request while you are
working through the implementation.</p>
<h3 id="keep-it-small">Keep it small</h3>
<p>With small code reviews, the reviewers will find it easier to hold the whole
change in their mind, which makes it easier to reason about what the change
does, and its impact. This results in:</p>
<ul>
<li>Faster reviews</li>
<li>Better reviews</li>
<li>Improved quality</li>
<li>Better velocity, i.e. quicker merges and development of features</li>
<li>Easier collaboration</li>
</ul>
<p>How small you ask? There is
<a href="https://graphite.dev/blog/the-ideal-pr-is-50-lines-long">evidence that the ideal PR is 50 lines (or fewer)</a>,
which might be too small. It is a good idea
<a href="https://dafoster.net/articles/2024/08/18/effective-code-reviews/">(1)</a>,
<a href="https://smartbear.com/learn/code-review/best-practices-for-peer-code-review/">(2)</a>,
however, to aim for PR&rsquo;s to be no more than 200 - 400 lines. The limit will
depend on factors like how verbose your language is (e.g. Java).</p>
<p>Split the PR if it:</p>
<ul>
<li>Is too large</li>
<li>Does more than &ldquo;one thing&rdquo; (e.g. two features, or a feature, and a bug fix)</li>
<li>Has high complexity, risk, or impact</li>
</ul>
<h3 id="creating-the-pr">Creating the PR</h3>
<p>Ensure the PR has more context than might be necessary, particularly if there
could be reviews from people who may not be fully aware of the motivations
behind the change. Ideally the reviewers are already aware of the feature, the
motivations, and the approach for solving the problem before they ever get the
request.</p>
<p>If the reviewers know to expect a PR and have a rough idea of what to expect
from it, it will be easier for them to plan for it, and to do the review.</p>
<p>Good idea of things to include in the PR description:</p>
<ul>
<li>Link to the issue/feature/story that is tackled, including details of:
<ul>
<li>Why is this being done?</li>
<li>What is the expected end result?</li>
</ul>
</li>
<li>Details of exactly what part of the above is being tackled, including details
of what has already been completed and what&rsquo;s next, if relevant.</li>
<li>Screenshots of the change</li>
<li>Video if relevant of how it works.</li>
<li>What questions should the reviewer answer for you?</li>
<li>Detailed instructions on how to test it. Another place where a video might be
helpful.</li>
<li>The impact of the change, including to:
<ul>
<li>Infrastructure</li>
<li>Costs</li>
<li>Maintenance</li>
<li>Support</li>
<li>Customers</li>
<li>Data</li>
<li>Regulations (e.g. GDPR)</li>
</ul>
</li>
<li>Identified risks, if any</li>
</ul>
<p>The smaller the change the easier it will be to be thorough about all the above.</p>
<p>Before assigning any reviewers, the final step is to do a <em>Self Review</em>. Put
yourself in the shoes of a reviewer and do a review of the whole PR, starting
with the above. It is better if a reviewer finds an issue instead of your
customer. Similarly, it is better if you find an issue instead of a reviewer.</p>
<h3 id="waiting">Waiting</h3>
<p>While waiting for the review, it is a good idea to do any pending reviews so
that you can help unblock others work. If there are none that you can contribute
to, you could use stacked PRs (aviator.co can help with this) to carry on with
your work. Avoid building up multiple stacks though as each stack will require
additional effort to keep in line with &ldquo;upstream&rdquo; changes.</p>
<h3 id="making-changes">Making Changes</h3>
<p>A good review is one which catches issues that you hadn&rsquo;t thought about. Better
to find them now than in production. Appreciate the time and effort that the
reviewers have put in to help you out.</p>
<p>Prioritise, discuss and implement the changes. Focus on the changes that are
easy to implement, then the ones that are crucial to be able to merge the PR.
Take a note of the remaining changes for subsequent PRs. It is a good idea to
<code>fixup</code> with git to curate your commits rather than having commits that
<code>fix stuff from review</code>.</p>
<p>Depending on your team guidelines, request re-reviews as required, but ensure
that you are not using your reviewers as someone who checks your work. It is
after all, a <code>Peer</code> review.</p>
<h3 id="merging-the-request">Merging the request</h3>
<p>Before you merge, ensure that nobody is currently in the process of reviewing
your code. Reviewing code can take time and it can be frustrating if a PR is
closed while in the middle of a review. It is important to communicate with your
team to avoid gaps in communication. The PR process does not remove the
requirements for communication.</p>
<p>Once you have a request ready to merge, go ahead and follow the team guidelines
on merging. Well done!</p>
<p>It is a good idea to appreciate the reviewers for their input and feedback.
Software development is easier when done collaboratively. When your reviewers
feel like their contributions valued, they are more likely to enjoy doing
reviews for you.</p>
<h2 id="as-the-reviewer">As the Reviewer</h2>
<p>Reviewing code is hard, but is worth the effort. Here are some strategies to
make reviews easier as well as more effective.</p>
<p>The quicker you can do the review, the better. The person who has requested the
review could be (partially) blocked until the review is complete. Furthermore,
lean methodology would consider it as waste the longer the code is not merged
in. This requirement, of course, has to be balanced with maintaining focus for
yourself and minimising interruptions.</p>
<p>Reviews are <em>not</em> about checking someone elses work or about grading it. It is
about learning (for both of you), collaborating and improvement (code and your
abilities). Bearing this in mind, LGTM (Looks Good To Me) reviews likely add the
least value.</p>
<p>If you do not spot any areas for improvement, consider pointing out areas that
stood out for you, or that you learned from. Review is collaborative and
appreciating someones work is an important part of collaboration and team
building.</p>
<h3 id="time-limit">Time Limit</h3>
<p>It is a good idea to limit a review session to no more than an hour.
&ldquo;<a href="https://en.wikipedia.org/wiki/Vigilance_%28psychology%29">Vigilance decrement</a>&rdquo;
is the decline characterised by reduced accuracy and slower response times when
performing tasks that require sustained attention. In fact, the clock test, a
1948 study showed a decline in ability by 10 - 15% after 30 minutes.</p>
<p>If a PR looks like it&rsquo;ll take longer than an hour to review, it may be better to
ask them to break it up.</p>
<p>Another option might be to split the review into multiple sessions.</p>
<h3 id="goals">Goals</h3>
<p>Why are you doing the code review?</p>
<p>If you are a more junior developer, or new to the team, you may be looking to
learn about the code base or engineering in general. When you learn something,
consider adding a comment. These comments can help to reinforce your learning,
validate your understanding and appreciate the requester. Code reviews aren&rsquo;t
only about improvement.</p>
<p>More senior developers may be more interested in preventing defects and
maintaining or improving the quality of the code base. Mentoring and coaching
could also be a part of that. Try to bear in mind that mentoring and coaching
can also apply to other reviewers.</p>
<p>Having an idea of what you are looking to get out of the review is important.
Remember that while doing a code review is hard, it is also a valuable
opportunity: to learn, to contribute, and to collaborate on curating the source
code which is an important asset owned by your team.</p>
<h3 id="communication">Communication</h3>
<p>Being constructive in your communication goes without saying and helps to build
a collaborative process focused on improvement.</p>
<h4 id="avoid-you">Avoid &ldquo;You&rdquo;</h4>
<p>To make reviews easier, it is a good idea to talk about the work and not the
person. One straightforward strategy you can use is to avoid the word &ldquo;You.&rdquo;</p>
<p>Let&rsquo;s try an example:</p>
<blockquote>
<p>You misspelled &lsquo;successfully&rsquo;</p>
</blockquote>
<p>How did that feel, compared to:</p>
<blockquote>
<p>sucessfully -&gt; successfully</p>
</blockquote>
<p>How about another one?</p>
<blockquote>
<p>Can <em>you</em> rename the variable to be more descriptive?</p>
</blockquote>
<p>compared to:</p>
<blockquote>
<p>Can <em>we</em> rename this variable to be more descriptive?</p>
</blockquote>
<p>Using &lsquo;we&rsquo; above also helps to reinforce the collaborative team nature of a
review.</p>
<p>There are of course exceptions, particularly when you want their opinion, but be
conscious that it does not come across as passive aggressive.</p>
<blockquote>
<p>What do you think about X?</p>
</blockquote>
<p>It might take a little while to break this habit, but it is worthwhile. If you
would like know more about this, you should look up Transactional Analysis (TA),
a psychoanalytic theory and therapy that can help with communication.</p>
<h4 id="avoid-value-judgments">Avoid Value Judgments</h4>
<p>Whether something is good, bad, right, or wrong is usually too subjective to be
constructive or valuable. Focusing on the why can be more helpful. Another
option is to make it clear that it is an opinion.</p>
<blockquote>
<p>This library is a bad choice</p>
</blockquote>
<p>can be improved:</p>
<blockquote>
<p>This library looks like it&rsquo;s not maintained, and could cause us issues. We
should use X instead.</p>
</blockquote>
<p>or even:</p>
<blockquote>
<p>I think this library is a bad choice because I did not enjoy working with it
before.</p>
</blockquote>
<p>By making it clear that it is an opinion, it makes it easier to talk about.</p>
<h4 id="ask-questions">Ask Questions</h4>
<p>Regardless of seniority or experience, if you do not understand how or why
something is the way it is, ask the question.</p>
<p>Code should be readable and easy to understand for everyone. The fact that you
had to ask might be indication that the code needs to change to be easier to
understand.</p>
<p>It is usually better to make the code easier to understand than to add a comment
with explanations.</p>
<h4 id="be-specific-and-offer-alternatives">Be Specific and Offer Alternatives</h4>
<p>When talking about improvements, strive to be specific, and to offer
alternatives.</p>
<blockquote>
<p>This function takes too many parameters</p>
</blockquote>
<p>Does not help the requester.</p>
<blockquote>
<p>Having so many parameters hurts readability and suggests that the function may
be doing too much. Can we refactor this method to simplify it?</p>
</blockquote>
<p>If you do not have a solution, it would be better to open a dialogue.</p>
<blockquote>
<p>I am worried that the number of parameters here hurts readability. Can we talk
about how we can address this?</p>
</blockquote>
<p>Collaboration is a powerful tool when it comes to improving quality of code and
working out effective solutions.</p>
<h4 id="communicate">Communicate</h4>
<p>If you are not going to be able to do a review or a re-review, let the requester
know so that they can carry on.</p>
<p>If there is something which is better reviewed synchronously, request a
call/meeting as relevant. Sometimes a quick 5min call can save a 20min
commenting conversation, not to mention potential misunderstandings.</p>
<h4 id="affirm--appreciate">Affirm &amp; Appreciate</h4>
<p>When you see something valuable or if someone has gone an extra mile, or maybe
only half a mile - call it out and appreciate them. Code reviews aren&rsquo;t only
about opportunities for improving the code. It&rsquo;s also opportunities to improve
the team cohesion, wellbeing and morale. By calling out good work, you will also
be encouraging it.</p>
<h4 id="invite-discussion">Invite Discussion</h4>
<p>Consider phrasing nontrivial comments as invitations to discussion rather than
being prescriptive. Collaborating to a mutually agreed outcome can not only
provide an improved solution, but can also lead to better ways of working.</p>
<h4 id="prioritise-feedback">Prioritise Feedback</h4>
<p>If you can prioritise your feedback, it can help the requester focus on the most
relevant items first. You could consider the following priorities:</p>
<ul>
<li>Blocker: Needs to be addressed before merge</li>
<li>Follow Up: Can be addressed in a subsequent PR, but should be addressed</li>
<li>Minor: Could be resolved in a subsequent PR if time allows.</li>
</ul>
<h3 id="big-items-first">Big Items first</h3>
<p>While your focus ability is still high, start with the big picture items. Are
there any blockers? Is there any reason this bit of code cannot or should not be
merged?</p>
<p>Are there any missing items?</p>
<ul>
<li>Documentation?</li>
<li>Tests?</li>
<li>Artifacts?</li>
</ul>
<p>After that, focus on the smaller items. As you get more senior, you may want to
consider focusing less on small or trivial issue. Your time may be better spent
encouraging and helping the more junior developers on the team to do reviews and
find and report those. If you find most or all of issues, you team may be
inclined to leave the reviews to you.</p>
<h3 id="test-the-change">Test the change</h3>
<p>It is a good idea to pull the changes yourself and test it. It can help identify
any assumptions about dev environments, locally installed packages and bugs that
the requester was perhaps too close to see.</p>
<h3 id="loop-in-others">Loop in others</h3>
<p>If you come across code or changes that could benefit from review by people not
currently on the list, it is a good idea to let the requester know and to bring
them in. The requester may have a reason for not including them, so it may be
worth checking with them first.</p>
<h3 id="things-to-consider">Things to Consider</h3>
<p>Try to consider all the impact this change could have, including:</p>
<ul>
<li>Maintenance</li>
<li>Support</li>
<li>Infrastructure</li>
<li>Security</li>
<li>Costs</li>
<li>Customer/User</li>
<li>Compliance</li>
<li>Scalability</li>
</ul>
<p>Other things to consider:</p>
<ul>
<li>Biases &amp; Assumptions: Is there anything the requester is too close to see?</li>
<li>Complexity: Could anything be simplified, or even better designed away?</li>
<li>Alternative solutions: Assume the author has considered them too, but might be
worth a discussion</li>
<li>Dependencies: The fewer the dependencies, the better. Can some of them be
removed?</li>
</ul>
<p>It may be impossible to consider everything, but it is good to be mindful of the
impact the change could have. It is also a good idea to document any potential
risks, and possible mitigation.</p>
<h3 id="post-merge">Post Merge</h3>
<p>Just because a PR has been merged does not mean that it no longer benefits from
review. Reviewing PRs after they have been merged provides the same benefits. It
is a good idea to work out how that process would work since platforms like
GitHub are not built to support this workflow as well as the gated merge.</p>
<p>From a lean methodology perspective, it would make sense to automate as many of
the checks as possible and automatically merge on pass. All reviews would then
be completed post-merge. This process would have the benefit that all features
are providing value at the earliest possible point.</p>
<h2 id="for-everyone">For Everyone</h2>
<p>It is important to integrate your code continuously. This process reduces waste
by:</p>
<ul>
<li>Making merges easier (fewer conflicts)</li>
<li>Potential defects are found sooner, and are easier to resolve</li>
<li>Validating the direction of the feature as well as the method (i.e. where are
we going and how)</li>
<li>Allow reuse of code earlier</li>
</ul>
<p>It may help to think of development more like crafting or curating software,
collaboratively, together.</p>
<h2 id="be-gracious">Be Gracious</h2>
<p>No matter your role in the team or how long you have been a part of it, the
cohesion of the team and the wellbeing of its members is crucial to its
effectiveness. The quality of what you build is also important, but by and
large, it is easier to fix software than it is to fix issues within a team.</p>
<p>Be mindful of actions that may negatively impact your or your teams wellbeing
and cohesion. Be aware of your ego and if it is getting in the way of
collaboration.</p>
<p>Be kind, courteous and considerate: Be gracious!</p>
]]></content:encoded></item></channel></rss>