πŸ“œ ⬆️ ⬇️

Review code in the comments

Review of the code is useful and can be done in different ways: by patch by mail, sitting side by side or using specialized tools / plugins. Each method has its pros and cons, but we offer another one that allows us to use what we already have.

Preconditions


The method will be of interest to a small team using a distributed version control system (git, mercurial, bazaar) with an embedded methodology for developing features / tasks / bugs in branches (for example, gitflow). Code editors in the team support parsing comments for certain keywords (for example, TODO). A full-featured specialized tools for reviewing the code can not be implemented, because they are paid and do not have a line in the budget; either free, but not easy to install, or have questionable usability; or in a particular case they may be a sparrow king-cannon.

Process


The general idea - features (bugs, tasks) are developed in separate branches, a la gitflow, and then published on a server - you can even central. The reviewer writes comments in the style of TODO, but with a special tag, for example β€œREV”:
')
$ourcoolcode = 123; // REV      ? echo $ourcoolcode; 

Comment syntax
 /** * $TAG $status $title * $commentor1 $comments * $commentorN $comments */ 

  • $ TAG - unique to the project code, not TODO, not XXX, etc, but, for example, REV. Must not exist in comments in the current project code.
  • $ status is an optional parameter that can indicate the status: β€œ+” - the question is closed or the problem is resolved; β€œ!” - we have a problem, and the number of characters may indicate the severity of the problem.
  • $ title - the title of the issue / problem.
  • $ commentor1 / $ commentorN - (optional) a certain designation of the authors of comments, in order to distinguish some comments from others.
  • $ comments - either comments of the author of the question / problem, when the title does not fit everything, or comments of the person who answers.

Comments can be either single-line or multi-line, depending on the specific language.

Any modern IDE can extract and filter a TODO. This is exactly what Eclipse and Netbeans can do, and JetBrains and other paid editors simply have to do it. As a result, you can change the comments in the branch, until everything becomes clear and they do not end. At the end of the process, when the code becomes better, the branch can be safely compressed (squash) and merged into the main one (develop). All comments at the end are erased and should not get into the code, which can be hugged.

Abstract example in vacuum




Advantages and disadvantages


Advantages of the method:


And of course the disadvantages (with variants of workarounds):


Conclusion


We emphasize that this method is not offered as one and the most correct, but is one of the options in certain conditions. If you know or have already used something similar, but have not formalized, describe it boldly, and improvements to the method are also welcome. Even if this method does not suit you, then perhaps it will push you to some other ideas.

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


All Articles