Saturday, February 6, 2010

Code Reviews

What are Code reviews?

Code reviews are excellent tools to detect and eliminate hard-to-find bugs, to increase code quality, to enforce collective code responsibility, and to spread knowledge.

The code review weeds out problems at several levels:

1. The overall design (we check the choice of algorithms and external interfaces).
2. The expression of that design in the code (its breakdown into classes and functions).
3. The code in each semantic block (we check that each class, function, and loop is correct, follows appropriate language idioms, and is a practical implementation choice).
4. Each individual code statement (each must follow project coding standards and best practices).

Code reviews can be:

Personal
The author carefully and methodically reviews his or her own work to make sure that it’s good. Don’t get this confused with casually reading your code after typing it; a personal code review is a more detailed and involved task.

One-on-one
You walk another programmer through your code. The other programmer checks the logic and looks out for faults as you lead through it. These reviews tend to be informal, driven by the author. The code is therefore approached from the author’s perspective: with his or her set of assumptions, rather than from a more objective, outside view.

Formal
Involving other programmers brings new expertise, more experience, and more eyeballs to the task and shifts the perspective from which the review is run. Large-scale reviews are consequently harder to coordinate and require greater overall effort, but they are more likely to root out problems. It’s difficult to delve this deeply in a personal review; often the author is too close to the code, and it’s easy to overlook flaws. This usually takes place in a formal meeting, but it can be run as a virtual review: online, with no physical meeting.

Each type of review can be used at a different time in the development process. One-to-ones might be used daily throughout code development, as an integration review before modifications are committed to the main source tree. Formal reviews are brought in toward the end of code development, as a final software quality audit.

[Source: Code craft: the practice of writing excellent code By Pete Goodliffe]

Few excellent resources to understand Code Reviews

Efficient Code Review - How do you do that?
Stack Overflow

Code Review FAQ
Openmrs

Software code reviews can be of immense value to any organization that is involved in developing software. But, code reviews can also be the source of many pitfalls and frustrations, with many related to an organization’s size and to what degree it is market focused, or proximity to the ultimate customer.

FutureWare was invited to a series of interviews. All of these interviews have been collected in this document.
FutureWare

Effective Code Reviews Without the Pain
Developer

Prepare to Succeed - A Guide to Effective Code Review
Better Software

Also See:
Code Review Checklist
Technical Review
Importance of Review
Pair Programming Review
Types of Review Process Structures
Difference between Formal & Informal Reviews
Deciding Whether to do Formal or Informal Reviews
Software Design Reviews
Formal Review & Informal Review
Walkthrough and Inspection
Peer Review
Software Management Reviews
Test Case review