Google open source code review specification: this code should be judged good or bad

Google open-source set of code review (Code Review) specification, which is a common set of Google engineering practical guide, covering almost all programming languages ​​and various types of projects, this specification represents the best long-term practical experience in development since Google collection, Google expressed hope that open source projects or other organizations can benefit from this specification.

Code review, also known as code review, if a team is using a workflow task branch, then write all the code completion and after the adoption of automated testing, before the code merge, it will start code review. The usual aim is to find defects in the system, and improve the overall quality assurance of software developers own level, all the tools and code review processes are built for this purpose. Code review the role agile teams are as follows:

  • Code review to share knowledge

  • You can better evaluate the work carried out by the code review

  • Code review can let you enjoy vacation

  • The new guide engineers through code review

Since the code review to be carried out numerous checks, looking for a good reviewer is very important. General changes for different parts of the list, will have different reviewers careful review. Of course, if pair programming, and your teammates can carry out high-quality code review, then write code that can generally be considered to have been a review. In addition, we can also face to face review, reviewers will ask developers questions.

According to Google's project description, code review specifications for the two separate documents, representing the best practices of two aspects:

  1. Code review's Guide
  2. CL Author Guide

In some of a number of terms used in the document, as follows:

  • CL: represent the "change list (changelist)", meaning the version control or have been submitted to an independent examination of the code being changed. Other organizations often called "change" or "patch"
  • LGTM: meaning "good in my opinion (Looks Good to Me)", which is the code reviewer said that at the time of approval CL

Next we look at what are the main contents of the two documents are:

1. Code reviewers guide - how code review

Code Review Guide would have been a complete document, but the author will be divided into six parts, the reader may need to read.

2.CL author of the guide --CL approval code review guidelines

CL-makers guide including the best experience some developers of code review, and these experiences can help you faster, higher quality to complete the assessment.

In the Google view, the purpose is to ensure that the overall code review code that Google code base level of health. Google the following rules as the standard code review:

In general, once the CL can improve the overall health of the code, even if imperfect CL, reviewers should also tend to approve the list. This is an advanced code review of all the principle guide. It also has some limitations, for example, if CL reviewers do not need to add some features, even if the code to do a good design, reviewers should not be passed.

No such thing as "perfect" Code, only better code. Reviewers should not require prior approval of each small part of CL's too perfect. Instead, the assessment should weigh the need and importance of the proposed changes forward to continue development. Reviewers requirement is continuing to improve, rather than the pursuit of the perfect code. CL as a whole, if it can improve system maintainability, readability and understandability, then do not because it is not perfect and postponed for several days or weeks update.

Reviewers should always leave some comments to express their lead to better performance practices. If these practices are not very important, we need to add the prefix "Nit:", so that the code writers know the content is negligible.

Review guide

Code review has a very important function, that is, to teach developers a number of development experience, regardless of language, framework or general software design guidelines. Always leave some comments to help developers learn some new knowledge, sharing of knowledge important part of the system code is to improve health status. Of course, if the reviewer's comments merely educational, and for standard requirements are less important, then still have to add the prefix "Nit:" a.

Judging Criteria

Technical facts and data to give priority to the views and personal style.

In the code style, Google code style guide is the most authoritative reference material. Style Guide is not in any code habits are a matter of personal style, but we should ensure that the basic style and Google style guide is the same.

Software design, almost no purely a matter of style, or purely personal habit. Many styles are based on some basic questions quasi-measure, they are not simply determined by the individual's point of view. In addition, if the code author proved equally effective in several ways by data or basic engineering principles, then the reviewer should accept the author's style. Otherwise, the choice or preference depends on the standard principles of software design.

If there are no other applicable rules, reviewers can ask the author's preference is consistent with the current code base, while not affecting the overall health of the code.

Resolve conflicts

In the code review, if any conflict, the first step should be the developers and reviewers to reach a consensus based on CL guide the project. When consensus is very difficult, developers and reviewers should communicate face to face, not just to communicate through the review comments. If you still can not solve the meeting to discuss, then they would expand the conference, we can exchange with code maintenance personnel, project managers and other developers, to reach a final consensus.

If you want to understand Google code review of this specification, you can view the project. At the following address:

https://github.com/google/eng-practices

Source: Almost Human

Guess you like

Origin www.oschina.net/news/109708/google-open-source-code-review