12

Disclaimer: There are some similar questions, but I didn't find any which touch specifically the problems you face while reviewing a large pull request.

Problem

I feel my code reviews could be done in a better way. I'm particularly talking about big code reviews with many changes across 20+ files.

It's pretty simple to catch obvious local code problems. Understanding whether the code meets business criteria is a different story though.

I have troubles following the thought process of the code author. It's pretty hard when the changes are numerous and spread across multiple files. I try to focus on the groups of files related to a particular piece of changes. Then review the groups one by one. Unfortunately the tool I use (Atlassian Bitbucket) is not very helpful. Whenever I visit a file, it gets marked as seen, even though it often turns out not to be related to the currently examined piece of changes. Not to mention that some files should be visited multiple times and their changes reviewed piece-by-piece. Also coming back to relevant files when you follow a bad path isn't easy.

Possible solutions, and why they don't work for me

Reviewing a pull request by commits often solves the size problems, but I don't like it since I'll frequently be looking at outdated changes.

Of course, creating smaller pull requests seems like a remedy, but it is what it is, sometimes you get a large pull request and it has to be reviewed.

You can also ignore logical aspect of the code as a whole, but it seems pretty risky, particularly when the code comes from an inexperienced programmer.

Using a better tool could be helpful, but I didn't find one.

Questions

  • Do you have similar problems with your code reviews? How do you face them?
  • Maybe you have better tools?
  • 3
    Why are those code reviews so large? For example, if they are the result of an automated refactoring, then instead of reviewing the commit, you check whether repeating the refactoring on the older commit produces an identical copy of the new commit, and then decide whether you trust the tool or not. So, reviewing a 1000-line diff all of a sudden becomes reviewing a 1-line command in an IDE and a decision whether to trust the IDE vendor. – Jörg W Mittag Nov 12 '18 at 1:51
  • If you have the pull to be able to do it, make it the code author's responsibilty to make code review easy. This means that authors should be mindful of squashing irrelevant commits, rewriting commits so they contain only one change, to separate major refactoring commits, and to order the commits in a way that makes sense for reviewers. – Lie Ryan Nov 16 '18 at 2:45
8

We had these problems and asking the question below has been working well for us:

Does the PR do one thing that can be merged and can be independently tested?

We try to break PRs by single responsibility (SR). After initial push back folks were surprised to find that even something small albeit single can be large.

The SR makes it really easy to review and also disseminates knowledge of the expected implementation.

This also allows for incremental refactors as more is added and PR turnaround time is drastically reduced!

I’d suggest breaking them up by SR if possible and see if it works for you. Takes some practice to do it that way.

11

Sometimes you can't avoid large pull requests - but you can be discerning as to who has what responsibility.

I treat pull requests as persuasive arguments. The Author is trying to convince me that the code should look and work this way.

As with any argument it should have a single clear idea. Its either:

  • a refactor,
  • an optimisation,
  • or new functionality.

If they are not being clear, then there is a pretty good chance that they do not understand it themselves. Open up the dialogue and help them break their argument down into its sub-arguments. If need be, its perfectly alright - even beneficial for them to recreate those commits, and offer more comprehensible and direct pull requests.

There will still be large pull requests, but with a clear argument its much easier to see what does not fit.

As for tooling, it is dependent on your organisation and process. BitBucket is a decent tool, whether its better or not depends on everything from your budget, hardware, requirements, through to your pre-existing processes, business rules, and various software adaptions you've already made to accommodate BitBucket. I'd start by looking through the documentation to see if the behaviour can be configured, maybe throwing out to the plugin community (or joining it by making a plugin to do that).

9

Don't review the complete pull request, but every commit. You'll acquire better understanding of the pull request anyway by doing it this way.¹

If commits are small, doing such review shouldn't be a problem. You follow the changes one by one through the commits, and you end up getting the full picture. There are drawbacks, such as that you'll sometimes review changes which will be undone a few commits later, but this shouldn't be a great deal.

If commits are large, then you should discuss it with the person who did those commits. Explain him why large commits are problematic. Listen to the other person's arguments about why he commits changes rarely: you may learn, for example, that he avoids doing commits because pre-commit hooks take too long, in which case this problem should be solved first.

Reviewing a pull request by commits often solves the size problems, but I don't like it since I'll frequently be looking at outdated changes.

You do, but this is a minor issue, and you should waste much less time reviewing code which will be undone a few commits later than the time you waste trying to figure out why the code was changed when reviewing a single file.

“Frequently” is vague, but if you find yourself spending too much time reviewing code which didn't found its way to the final revision of the pull request, you may use two techniques:

  • Go quickly through all the commits once, just reading the commit messages. This way, when studying a particular commit, you may remember that a commit message somewhere later said that the change you're looking at was reverted.

  • Have a side-by-side view of the latest version of the file (although in many cases, for large commits, (1) the files could be radically different and (2) the files may be renamed or the large blocks of code may be moved elsewhere, making it difficult to find the matching file).

  • Either ask committers to squash commits when it makes sense, or have a specific commit message conventions where one commit undoes a part of another one, and do your review taking in account several following commits.


¹ For instance, imagine you're looking at a file where some variable has been renamed. What does it tell you? How should you review this change? If you were reviewing it commit by commit, however, you would see that a single commit renamed the same variable in twenty files, and the comment indicates that the name was changed in order to use the proper business term. This change makes perfect sense and is possible to review.

  • 1
    @JörgWMittag: thank you for your comment. The OP claimed that he doesn't want to do per-commit reviews because he would see outdated changes, which is true, but shouldn't be as problematic as having all the issues related to per-file review. Since my answer was unclear on that, I added a section to specifically address this point. – Arseni Mourzenko Nov 12 '18 at 9:29
2

Work out what you are trying to achieve with reviews of pull requests and see if there is an alternative.

For instance you might want to

  • Ensure standards are followed
  • Check functionality is correct
  • Make sure more than one person understands the code
  • Train juniors

etc etc.

Some of these might be better served by other things, and even just understanding the reasons allows you to limit the scope of your checks.

For example if I'm checking every line so I can suggest and discus changes for training, then I can skip that on a large PRs done by seniors

If I need to understand the code, maybe do pair programming on large features and limit the code review to a standards check.

You don't need to check all the things on every PR as long as you have a layered approach to QA

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.