📜 ⬆️ ⬇️

Comparison of code review techniques

I think many developers are familiar with the concept of code review or code review in Russian (this term is also translated as code review, code inspection or code review - further, the “code review” option will be used for consistency). Recently, I was faced with the need to "sort through" and classify knowledge on this topic. The result is this article. I hope it will be useful, as well as help to introduce code reviews into its production process to those who only think about it.
wtf per minute
Code review is one of the most effective methods for finding and eliminating program defects. Reviews are conducted by humans, which allows finding a wide class of errors, including those that are difficult to detect or are not detected at all by automatic means. Of course, the review of the code does not cancel the use of code analyzers or other methods of error detection, for example, unit-testing. Unfortunately, there is no method that alone would ensure the detection of all program defects (in studies, the effectiveness of code review is usually estimated at 30-50% of detected errors in the application).

Finding errors is not the only task of reviewing code. In addition, the review of the code has several positive properties:


You have to pay for all this with the time that could be spent on coding. Nevertheless, on projects designed for at least some prospect, the time spent in the future will return a hundredfold due to the creation of an initially high-quality product, instead of a convulsive “dopilka” later.

The following types of code reviews can be distinguished:
')

Consider each option separately.

Formal code inspection


A formal code inspection is, as the name suggests, a formalized code review procedure. According to McConnell, it looks like this.

The inspection coordinator designates the date of the inspection meeting and inspectors, who must independently examine the inspected code fragment before the meeting. At the appointed time, the coordinator of the inspection, the secretary, the author of the code and the inspectors gather. Some of the inspectors or the supervisor begin to read the code line by line (for convenience, it is advisable to print it in advance along with the line numbers). The inspectors point out the problems they found, the author of the code answers the questions of the inspectors - if everyone agrees that there is a mistake, the secretary writes it down. The coordinator of the inspection monitors the process as a whole, for example, so that discussions of one error are not delayed. Upon termination of inspection the report with its results is formed.

A more detailed example of a formal inspection can be found here .

Advantages:


Disadvantages:



Informal code inspection


Informal inspection, unlike formal inspection, does not have clear rules. For example, this may happen as follows: the author of the code, before publishing it, calls the first developer to his computer, where he shows and tells what he wrote. The examiner tries to grasp into what is written, asks questions and expresses his thoughts. Of course, with this method, the efficiency will not be very high, but such an inspection takes little time.

Advantages:


Disadvantages:



Code reading


Reading a code is an independent study by a developer of someone else's code without the presence of the author. This practice is the simplest and most common of those described here - I think that any developer somehow came to read someone else's code. Not to mention the world of Open Source, where it is often the only available method for reviewing code.

Advantages:


Disadvantages:



Pair programming


Pair programming is an extreme method of reviewing code — a review that is carried out constantly: two developers behind one computer, behind one set of mouse and keyboard, together solve one problem. Widespread pair programming received after the emergence of the methodology of extreme programming, although actively used before. Often, pair programming is used spontaneously: I think many had to approach another developer behind a computer to help solve a complex task.

Advantages:


Disadvantages:


I want to add a few words to the above. As you can see some disadvantages stem from the merits. This is not surprising - the pair programming method is not simple enough, as it may seem at first glance, and not all its properties are obvious. Therefore, starting to work in pairs, do not expect instant results. Only after gaining some experience, pair programming will begin to bear fruit, and moreover, it will be possible to minimize some of the negative effects.

What to choose?


Now you can try to decide which method and in which case should be used.


As you can see, there are enough options - you can choose the most suitable method for yourself. In addition, no one forbids combining techniques (for example, one part of the team works in pairs, the other part alone, but the code written by them is necessarily inspected). You can start with simpler methods and gradually move to complex ones - the main thing is to start, and I think, positive effects will not keep you waiting.

Literature


  1. Perfect code (Code complete). Steve McConnell. Chapter 21. Co-construction.
  2. Extreme programming: setting the process. From the first steps to the victorious end (Extreme Programming Applied: playing to win). Ken Auer, Roy Miller (Ken Auer, Roy Miller). Chapter 14. We stop working alone.

Source: https://habr.com/ru/post/151450/


All Articles