Code Review Can Be Better

99 points by matklad


ianthehenry

Hey! I am the person who gave that talk eight years ago (gosh).

I think it’s important to the workflow (as you discovered) that the changes to CR comments are intermingled with changes to the code – when you make a commit that addresses a comment, you atomically XCR the comment back to the original person in that same commit. No friction from wrangling the CRs separately.

When I’ve thought about bringing CR-comments to the outside world, while still preserving legible history, I have imagined doing it as a “cleanup” pass: do the review, and once all comments have been addressed, rewrite each commit in the branch without the CR comments (removing any empty commits that result), and then go through and squash things until your history looks reasonable, then merge that. Before Jane Street I was a big fan of pushing fixup commits during review; if you address CR issues as fixup commits, then once those fixup commits have the comment bits stripped out, they should apply cleanly. In my head this would work, but I’ve never tried it. I guess you could also just add CR comments in the original commit that you think should be fixed up… but I dunno. Jane Street kinda treats “one branch” as the atomic unit of a change rather than “one commit” which makes a lot of this simpler.

You could keep the original branch around (pre-squash) with some separate archived branch name or something so that you can consult the comment history, but we basically just try to make sure that anything interesting/valuable in the CR history survives as a real comment in the code. We don’t treat all CR comments themselves as part of the historical record, the same way that we don’t e.g. record every in-person conversation about the code. Occasionally you’ll run across comments like this:

(* person1: why do we do this?
   person2: a long and detailed explanation of why we do this
   person1: but why don't we do x instead?
   person2: x wouldn't work because... *)

Which you can tell was someone who just converted a CR into a regular comment instead of deleting it or rewriting it as a more normal comment. Dialogues can make good documentation!

The “brain” part of Jane Street’s review system (“remembering what I’ve already reviewed as a literal diff”) makes it easy to “fearlessly” squash and rearrange history and be confident that you haven’t changed anything about the final state of the code. It’s… technically easy to keep track of that… but actually adopting that requires some way to visualize ddiffs which makes it kinda high cost to try out. I’m not even sure if Jane Street’s open-source patdiff includes the ddiff stuff…

borisk

Why not ditch GitHub PRs entirely and just use git? This is how we (the build2 project) do it:

The biggest inconvenience of this approach that I can think of is the need to periodically rebase this branch on new commits in master.