Sun
22
Feb '09
Code reviews work
by Frank Spychalski filed under articles, comments, google

Seems like nowadays I only write blog posts in response to other blog articles… But I hope this is better than not writing at all. Ted Neward asks if code reviews do actually work because evidence suggests, that the scientific review process does not.

Only 8% members of the Scientific Research Society agreed that “peer review works well as it is”. (Chubin and Hackett, 1990; p.192).

“A recent U.S. Supreme Court decision and an analysis of the peer review system substantiate complaints about this fundamental aspect of scientific research.” (Horrobin, 2001)

Horrobin concludes that peer review “is a non-validated charade whose processes generate results little better than does chance.” (Horrobin, 2001). This has been statistically proven and reported by an increasing number of journal editors.

But, “Peer Review is one of the sacred pillars of the scientific edifice” (Goodstein, 2000), it is a necessary condition in quality assurance for Scientific/Engineering publications, and “Peer Review is central to the organization of modern science…why not apply scientific [and engineering] methods to the peer review process” (Horrobin, 2001).

Chubin, D. R. and Hackett E. J., 1990, Peerless Science, Peer Review and U.S. Science Policy; New York, State University of New York Press.

Horrobin, D., 2001, “Something Rotten at the Core of Science?” Trends in Pharmacological Sciences, Vol. 22, No. 2, February 2001. Also at http://www.whale.to/vaccine/sci.html and http://post.queensu.ca/~forsdyke/peerrev4.htm (both pages were accessed on February 1, 2009)

Goodstein, D., 2000, “How Science Works”, U.S. Federal Judiciary Reference Manual on Evidence, pp. 66-72 (referenced in Hoorobin, 2000)

This sounds so true to me. I heard way more than one story from Ph.D. students where the professors who were supposed to review papers just forwarded this work to their slaves.

But the fact that academic peer reviews are possibly a failure should not be used to argue against the usefulness of code reviews.

As a reviewee
My first project at Google was written in Python. I had never written a single line of Python before. The feedback I got from the first few reviews helped me learn a lot about Python in a very short time. I don’t know how many times I got these “Yes, this would work but if you replace these 6 lines with that short statement it would work, too” comments.

The same is true for my second project in C++. I have written some C++ before but this was for my Diploma thesis and the code was far from professional. Again the feedback I got from my reviewers helped me learn C++ a lot faster than I would have otherwise. This project was a lot bigger than the first one so I got a few “we already have this implemented here” comments.

As a reviewer
I usually don’t pay that much attention to our coding conventions but my pet peeve is looking out for missing comments. Every time I have to think about a single line of code, this is a pretty good signal that a comment is missing.

Reviewing other people’s code makes sure that I have at least a little knowledge about the areas of our project I do not work on directly.

Conclusion
Code reviews take time and need the proper tool support. But if it is done right, they are useful and help in a couple of different areas:

  • Learning a new language or about new piece of code.
  • Avoiding code duplication.
  • Making sure code is documented.
  • Distribute the knowledge.

Any comments? Or questions? Just leave a Reply: