Pull Request Interactions

I try to regularly review and provide feedback on pull requests for open source projects that I’m involved in. Here are some recommendations that hopefully reduce the number of round-trips on reviews.

Code conventions

Most projects have a CONTRIBUTING file of some sort, which describes the conventions in the project. Please skim and follow the conventions.

Explain the why

A PR should explain what it is doing and why that is useful. In many cases, it should have an associated issue that describes the problem that the PR is trying to solve.

The why matters in particular when the change is a feature addition, or a refactoring. Explain what is wrong with the current code, and how the change improves it.

Bad code takes more time to review

Code that is badly written is hard to review. It’s often hard to understand what it is doing. Because of that, it also requires a lot more time and effort to clearly describe what is wrong with it, and how it should be improved.

On the other hand, code that is well written is much easier (and pleasant!) to review. And that often results in it being reviewed and merged much faster.

Keep PRs small

PRs are ideally self-contained and as small as possible. If you’re adding a new feature, avoid including formatting improvements (even if correct) or unrelated bug fixes.

For example, if you’ve found two bugs in a project, then that should generally be two separate PRs. Each PR fixing one bug, and ideally adding a unit test that proves the bug is fixed. This allows the PRs to be reviewed and merged independently. If there are issues with the fix for one bug, than the other PR can still be merged, different people can be reviewers for each of the PRs, etc.

Smaller PRs also require less time to understand; I might be able to review and merge a 10 line change in a quick break, but need to schedule time to review a 500 line behemoth.

Unrelated formatting changes make the PR longer and thus more work to review for no good reason, so they’re best avoided. Once merged, they also confuse tools like “git blame”.

Be your own reviewer

Before submitting a PR, try to review it yourself. Look at the diff, and ask yourself if the change is clear, if the commit messages are good, if there are any unrelated changes, if the code is well formatted, etc. If you find issues, fix them before submitting the PR.

This saves time for both you and the reviewer. The alternative is that the reviewer will find the issues, and ask you to fix them, which means that you have to wait for the review, then make the changes, then wait for another review, etc. It also takes up their valuable time, which they could be using to review other PRs instead.

On reformatting

Generally speaking, please avoid reformatting changes. Most projects use a particular style for a reason. There are plenty of tools nowadays to reformat files automatically.

If you must, split the formatting changes into a separate PR, and have that merged separately. That way, the formatting changes can be reviewed and merged independently, and they won’t get in the way of the review of the actual change. Ideally, add the commits that do the formatting changes to a file like .git-blame-ignore-revs, so that they won’t show up in “git blame” output.

Ignore files

Ignore files should cover files that are generated by the build system, or that are generated by something specific to the project. Please don’t add files that are just standard metadata generated by your editor or IDE - those should be added to your personal global ignore file. Otherwise every project has to maintain a list of files generated by all possible editors and IDEs, which is a lot of noise for little benefit.

If you don’t have a global ignore file, consider adding one. For example, for git, you can add a global ignore file like this:

console:

git config --global core.excludesfile ~/.gitignore_global
echo ".idea" >> ~/.gitignore_global

Larger changes

If you’re planning to make a large change to the codebase, consider filing an issue and describing what you’re planning to do. That gives the maintainer(s) a chance to provide feedback before you invest significant time changing things. It also makes it easier to review any PRs later that implement the change, since there is already a high-level description of it.

If you are submitting a large change that is more than a couple of hundred lines, consider splitting it into multiple PRs. Ideally these PRs are independent of each other, so that they can be reviewed and merged independently. If they can not be independent, then stack them - each PR builds on the previous one, and the reviewer can review them in order. Some code review tools support displaying stacked PRs in a nice way.

This is beneficial for both the reviewer and the author. It allows the reviewer to review the changes in smaller chunks (which it’s easier to find time for) and makes it easier to understand the changes. For the author, it means that they can get feedback on the first PR before investing time in the next one, and it also allows them to get code landed - rather than waiting for the entire large change to be reviewed and merged.

The larger the change, the more likely it is that there will be some issues with it, and that will hold up the entire change. If the change is split into multiple PRs, then only the PR with the issue will be held up, and the other PRs can still be merged.

AI tools

AI tools can be a great help in writing code, but they also make it very easy to generate lots of code with little effort. This has potential of massively shifting the balance of effort in a PR from the author to the reviewer.

Whether you use AI tools or not, you are on the hook for the code you submit. That means that you should carefully review the code generated by AI tools, and make sure that it is as good as code you would write yourself. Make sure you understand the problem space and your solution well. In particular, the change should be as a minimal as possible, since AI tools seem to want to be very verbose.

There are some specific patterns that I have seen in AI-generated code that are often problematic:

  • Don’t overdo comments. Don’t state what the code is doing, but add context where that is not obvious.
  • Keep PR descriptions, issues and commit messages short and to the point. The more text yuo add, the more time it takes for other people to read.
  • You don’t need to tell me in the PR description what your PR changes, I can see that in the diff. Instead, explain why the change is useful and why you made the choices you did.
  • I don’t care that you ran 342 tests and that they all passed. That’s what the CI will tell me.
  • LLMs will often leave comments that are musings on what they’re doing. There is no point in saying that the code is using a set because a list was too slow. Instead, explain why a set is the right data structure for the problem at hand.

I also like hatch’s brief policy on LLM use:

  • All AI usage in any form must be disclosed. You must state the tool you used (e.g. Claude Code, Cursor, Amp) along with the extent that the work was AI-assisted.
  • The human-in-the-loop must fully understand all code. If you can’t explain what your changes do and how they interact with the greater system without the aid of AI tools, do not contribute to this project.
  • Issues and discussions can use AI assistance but must have a full human-in-the-loop. This means that any content generated with AI must have been reviewed and edited by a human before submission. AI is very good at being overly verbose and including noise that distracts from the main point. Humans must do their research and trim this down.

Parsing my feedback

I often ask questions on PRs. Often the best way to respond to those is to either improve the code so it is clearer, or to add a comment in the code or to the PR. This way, context is preserved for future readers - who may well have the same question as I did.

Pushing back

In general, please accept feedback in good faith. I may have a different perspective on the code than you do, especially with my maintainer hat on, so I will be asking for changes with different background in mind. If you don’t understand why I’m asking for a change, please ask.

Please push back if you strongly disagree with my feedback. I might be wrong, or may have misunderstood something.

Ping me

If you’re waiting on a follow-up from me for more than a week or two, it’s most likely that your PR has dropped off my radar. Please do ping me.

Enjoy the process

Having your code reviewed should not be a stressful or frustrating experience. It can be a great way to learn and to discover new ways of doing things.

Comments