How I Review Code

30 Apr 2014 | Five-minute read


For the group I work in at National Instruments, every piece of code we commit is reviewed by at least someone else. I’ve wrote before about why I think code reviews are important. Since I do many (or most) of the reviews, I think it is really useful for my colleagues to know how I do the review, and what I care most about.

I’ll describe my overall process, the types of comments I tend to give, and share some tips for making the code review easier. This isn’t a complete list, but should give you an overall idea of how I work and what I care most about.

My Review Process

Pass 1 - Details

Generally, I’m most interested in the overall structure, but it’s hard to get that picture when I don’t know what changed. Usually, I’ll go through the code and look at everything that changed. This is where I notice things like function names, syntax. Can you write the code a little differently that is easier to read? Can you make things private? Generally anything small and isolated.

Pass 2 - Overall Structure

The first pass helps me understand all the little pieces that changed. But I understand them independently. After that, I’m interested in the big picture. (This is the part I care most about.)

It is pretty common in this second pass that I delete comments I made initially. I do my best to understand the code, but as we all know, it is often easier to see how the code works by running it. Since I don’t run every piece of code, I sometimes make mistakes in my understanding. Just tell me I’m wrong and I’ll learn.

Types of Comments

I try to give three types of comments: “change to A”, “questions”, and “general comments”. I’ve been trying to figure how to differentiate between these, and I think I still improve significantly.

I’m also sometimes wrong or unsure, but I think it is better to be wrong than ignore a real issue. Where I’m wrong, please tell me so!

Change to A

You can identify these because I use very direct language. Usually I think something can be improved (or is even a bug). Usually the change is pretty clear.

Questions

You can identify these because the comment has a question (and usually a “?”). In these, I’m asking a question. You might the right, or I might be right. It probably makes sense to discuss these in person. Since you submitted the review, it is usually your responsibility to start the discussion. But, I’m always happy to have it.

General Comments

These are probably the hardest to identify. Sometimes the are written in future tense. “You will need to change this in the future.” I don’t expect these to be fixed in the review, but of course you can. These are my prediction of the future and it is a suggestion that you might want to change now, in the next change you submit, or sometime in the future.

Positive Comments

There ‘s one more type that is my favourite comment type to give. If I really like something, I’ll tell you.

Misc Tips