Code Review Is Peer Review

Contents
  1. Why you can't check your own work
  2. What science figured out
  3. The mapping is almost exact
  4. The same failure modes, too
  5. What this means for how you review
  6. Not a ritual

Where engineering meets epistemology.

Every programmer has had this experience. You write a function, read it over three times, run it, and you are sure it is correct. You send it for review. Within five minutes a colleague points at a line and asks: what happens here when the list is empty?

Nothing in your head was wrong. You are not stupid, and you are not careless. You simply could not see it. And the reason you could not see it is the same reason science invented peer review.

Why you can't check your own work

When you read your own code, you don't read the code. You read what you meant to write. Your brain fills in the intent and skips over the text. The same thing happens when you proofread your own essay and miss a doubled word that a stranger spots at once.

This is not a personal failing. It is how minds work. The author of a piece of work carries a model of it in their head, and that model is exactly what they check the work against. Any error that is also in the model is invisible. The off-by-one you made because you misunderstood the API is the same off-by-one you will "verify" when you read it again, because the misunderstanding is still there.

Add to that the ordinary human biases. We are attached to what we made. We want it to be done. We look for confirmation that it works and stop looking once we find some. A scientist who has spent three years on an experiment is in exactly the same position as a programmer who has spent three days on a feature: the person least able to judge the work is the person who did it.

What science figured out

Science did not become reliable because scientists are unusually honest or unusually smart. It became reliable because it stopped trusting individuals and built procedures around them.

Peer review sends a paper to people who did not write it and asks them to find what is wrong. Replication asks a different lab, with different equipment and different assumptions, to get the same result. Publication exposes the method so anyone can attack it. None of these assume the original author is wrong. They assume the original author is the one person who can't tell.

I argued in Rationality Is the Exception that reliable reasoning runs on scaffolding like this, not on the good intentions of the people inside it. Science is not a group of rational people. It is a set of institutions that produce rational results out of ordinary, biased, attached people.

Software engineering arrived at the same institutions, mostly by trial and error, and mostly without noticing that it was rediscovering epistemology.

The mapping is almost exact

Look at what a healthy engineering team does and lay it next to what science does.

Code review is peer review. Someone who did not write the change reads it before it is accepted, and the change does not go in until they are satisfied. The reviewer's job is not to admire the work but to find the problem the author couldn't see.

Tests are replication. A test is a claim that the code does what it says, written in a form anyone can rerun at any time. A result that only works on the author's machine is like an experiment only one lab can reproduce: it is not yet knowledge.

Continuous integration is the reproducibility requirement. A clean machine, with nothing the author forgot to mention, builds the code from scratch and runs every check. "It works for me" is the software version of an unpublished method.

Open source is publication. The kernel mailing lists, where patches are posted publicly and torn apart by strangers, look much more like a scientific journal than like a company. I wrote about that resemblance back in 2012, in Basic Software Is Turning Into Academia. Linus's law, "given enough eyeballs, all bugs are shallow", is a claim about peer review.

Version control is the lab notebook. Every change is recorded, dated and attributed, so when something breaks you can find out exactly what changed and who reasoned about it.

The same failure modes, too

The parallel holds for the failures as well, which is the strongest sign that it is real.

A reviewer who approves a thousand-line change after two minutes is doing what a referee does when he waves through a paper from a famous lab. The review happened on paper and not in fact. A rubber-stamp culture produces code that has been "reviewed" the way some journals have "peer reviewed" papers that were later retracted.

Reviewers in both worlds check what is easy to check. In code, people argue about variable names and brace placement while the race condition goes through untouched. In science, referees argue about the phrasing of the abstract while nobody reruns the statistics. This is sometimes called bikeshedding, after the committee that spends an hour on the color of the bike shed and five minutes on the nuclear plant.

And in both worlds, the gate is only as good as what it is allowed to check. A test suite that nobody is allowed to fail, where a red build gets fixed by turning the check off, is like a journal that publishes only positive results. It looks rigorous and it certifies nothing.

What this means for how you review

If code review is peer review, a few things follow.

Review the reasoning, not just the text. A good referee asks whether the conclusion follows from the evidence. A good reviewer asks whether the code does what the change claims, under the conditions it will actually meet: the empty list, the network that times out, the second user who clicks at the same moment.

Small changes get real review. A referee can evaluate one claim carefully. Nobody can evaluate fifty claims bundled into one paper. Keep changes small enough that the reviewer can actually hold them in their head.

The author's seniority is irrelevant. Science works because a graduate student can refute a Nobel laureate. A team where the senior engineer's code goes in unreviewed has decided that some people's errors are invisible on purpose.

Being corrected is the system working. A scientist whose paper comes back with objections has not been insulted. A programmer whose pull request comes back with comments has not failed. The review found the error before reality did, which is the entire point.

Not a ritual

Many teams treat code review as a bureaucratic step, a box to tick before merging. Many scientists feel the same about peer review. Both are mistaking the procedure for a formality.

It is not a formality. It is the answer to a real problem: no one can see their own mistakes, and the cost of a mistake nobody saw is paid later, by someone else, at a higher price. Science found a solution to that problem over three centuries. Software found the same solution in a few decades. The solution is the same because the problem is the same.

So when someone asks why your team bothers with code review, the answer is not "because the process says so". The answer is the one science gives: because the person who wrote it is the last person who should be trusted to say it is right.