審查指南 最新版本_代碼審查-最終指南

審查指南 最新版本

by Assaf Elovic

通過阿薩夫·埃洛維奇

代碼審查-最終指南 (Code Review — The Ultimate Guide)

構建團隊代碼審查流程的終極指南 (The ultimate guide for building your team’s code review process)

After conducting hundreds of code reviews, leading R&D teams and pushing several unintentional bugs myself, I’ve decided to share my conclusions for building the ultimate code review process for your team.

在進行了數百次代碼審查,領導研發團隊并親自解決了一些無意的錯誤之后,我決定分享我的結論,以為您的團隊構建最終的代碼審查流程。

This article assumes you know what a code review is. So if you don’t, click here for a great intro.

本文假設您知道什么是代碼審查。 因此,如果您不這樣做, 請單擊此處獲取出色的介紹。

Let’s quickly state some straightforward reasons as to why you should do code reviews:

讓我們快速說明為什么要進行代碼審查的一些直接原因:

  1. Can help reduce bugs in code.

    可以幫助減少代碼中的錯誤。
  2. Validate that all coding requirements have been filled.

    驗證是否已滿足所有編碼要求。
  3. An effective way to learn from peers and get familiar with the code base.

    向同齡人學習并熟悉代碼庫的有效方法。
  4. Helps maintain code styling across the team.

    幫助維護整個團隊的代碼樣式。
  5. Team cohesion — encourage developers to talk to each other on best practices and coding standards.

    團隊凝聚力-鼓勵開發人員就最佳實踐和編碼標準相互交流。
  6. Improves overall code quality due to peer pressure.

    由于同伴的壓力,提高了整體代碼質量。

However, code reviews can be one of the most difficult and time-consuming parts of the software development process.

但是,代碼審查可能是軟件開發過程中最困難,耗時的部分之一。

We’ve all been there. You might have waited days until your code was reviewed. Once it was reviewed you started a ping pong with the reviewer of resubmitting your pull request. All the sudden you’re spending weeks going back and forth. You are context switching between new features and old commits that still need polishing.

我們都去過那里。 您可能已經等了幾天,直到代碼被審查。 一經審核,您就可以與審核員開始乒乓球,重新提交您的拉取請求。 突然之間,您要花費數周的時間來回移動。 您正在新功能和仍需要完善的舊提交之間進行上下文切換。

If the code review process is not planned right, it could have more cost than value.
如果沒有正確計劃代碼審查流程,那么成本可能會超過價值。

This is why it’s extremely important to structure and build a well-defined process for code reviews within your engineering team.

這就是為什么在您的工程團隊中構造和建立定義良好的代碼審查流程極為重要的原因。

In general, you’ll need to have in place well-defined guidelines for both the reviewer and reviewee, prior to creating a pull request and while it’s being reviewed. More specifically:

通常,在創建拉取請求之前和正在審閱期間,您都需要為審閱者和受審者都制定明確的準則。 進一步來說:

定義用于創建拉取請求的條件。 (Define perquisites for creating pull requests.)

I’ve found that the following greatly reduces friction:

我發現以下可以大大減少摩擦:

  1. Make sure code compiles successfully.

    確保代碼成功編譯。
  2. Read and annotate your code.

    閱讀并注釋您的代碼。
  3. Build and run tests that validate the scope of your code.

    建立并運行測試以驗證代碼范圍。
  4. All code in codebase should be tested.

    代碼庫中的所有代碼都應經過測試。
  5. Link relevant tickets/items in your task management tool (JIRA for example) to your pull request.

    將任務管理工具(例如JIRA)中的相關票證/項目鏈接到您的請求請求。
  6. Do not assign a reviewer until you’ve finalized the above.

    在完成上述工作之前,請勿分配審閱者。

定義受審者職責 (Define reviewee responsibilities)

While the reviewer is last in the chain of merging your PR, the better it’s handed over by the reviewee, the fewer risks you’ll run into in the long term. Here are some guidelines that can greatly help:

雖然審閱者在合并您的PR鏈中處于最后一位,但審閱者交出的越好,從長遠來看,您遇到的風險就越少。 以下是一些可以大大幫助您的準則:

  1. Communicate with your reviewer — Give your reviewers background about your task. Since most of us pull request authors have likely been reviewers already, simply put yourself in the shoes of the reviewer and ask, “How could this be easier for me?”

    與您的審閱者交流 —為您的審閱者提供有關您任務的背景。 由于我們大多數人的拉動請求作者可能已經是審稿人,所以只需將自己放在審稿人的面前,然后問:“這對我來說會更容易嗎?”

  2. Make smaller pull requests — Making smaller pull requests is the best way to speed up your review time. Keep your pull requests small so that you can iterate more quickly and accurately. In general, smaller code changes are also easier to test and verify as stable. When a pull request is small, it’s easier for the reviewers to understand the context and reason with the logic.

    提出較小的提取請求 - 提出較小的提取請求是縮短審核時間的最佳方法。 保持拉取請求較小,以便可以更快,更準確地進行迭代。 通常,較小的代碼更改也更易于測試和驗證是否穩定。 當拉取請求較小時,審閱者更容易理解邏輯的上下文和原因。

  3. Avoid changes during the code review — Major changes in the middle of code review basically resets the entire review process. If you need to make major changes after submitting a review, you may want to ship your existing review and follow-up with additional changes. If you need to make major changes after starting the code review process, make sure to communicate this to the reviewer as early in the process as possible.

    避免在代碼檢查期間進行更改 - 代碼檢查過程中的主要更改基本上會重置整個檢查過程。 如果您在提交評論后需要進行重大更改,則可能需要發送現有的評論并進行其他更改。 如果您需要在開始代碼審查過程之后進行重大更改,請確保在過程中盡早將此信息告知審查者。

  4. Respond to all actionable code review feedback — Even if you don’t implement their feedback, respond to it and explain your reasoning. If there’s something you don’t understand, ask questions inside or outside the code review.

    響應所有可操作的代碼審閱反饋 -即使您不執行他們的反饋,也要對其進行答復并解釋您的推理。 如果您不了解某些內容,請在代碼審查的內部或外部提出問題。

  5. Code reviews are discussions, not dictation — You can think of most code review feedback as a suggestion more than an order. It’s fine to disagree with a reviewer’s feedback but you need to explain why and give them an opportunity to respond.

    代碼審查是討論,而不是聽寫 -您可以將大多數代碼審查反饋視為建議,而不是命令。 可以不同意審閱者的反饋,但您需要解釋原因并給予他們回應的機會。

定義審閱者職責 (Define reviewer responsibilities)

Since the reviewer is last in the chain before merging the code, a great part of the responsibility is on him for reducing errors. The reviewer should:

由于審閱者在合并代碼之前是鏈中的最后一員,因此減少錯誤的責任很大。 審稿人應:

  1. Be aware to the task description and requirements.

    注意任務說明和要求。
  2. Make sure to completely understand the code.

    確保完全理解代碼。
  3. Evaluate all the architecture tradeoffs.

    評估所有架構權衡。
  4. Divide your comments into 3 categories: Critical, Optional and Positive. The first are comments that the developer must accept to change, and the latter being comments that let the developer know your appreciation for nice pieces of code.

    將您的評論分為3類:關鍵,可選和肯定。 第一個是開發人員必須接受才能更改的注釋,第二個是使開發人員知道您對精美代碼的贊賞的注釋。

Also, avoid many comments and use Github review instead (see example below).

另外,請避免使用大量評論,而應使用Github評論(請參見下面的示例)。

When you have several comments, you should use the review option in Github, instead of comment each of them separately, and notify the developer (PR owner) when you’re done.

當您有多條評論時,應使用Github中的review選項,而不是分別評論每條評論,并在完成后通知開發人員(公關所有者)。

Finally, I’ve found that asking the following questions is a great tool for an overall better and easier reviewing process:

最后,我發現提出以下問題對于整體上更好,更輕松地進行審核是一個很好的工具:

  • Am I having difficulty in understanding this code?

    我在理解此代碼時有困難嗎?
  • Is there any complexity in the code which could be reduced by refactoring?

    代碼中是否存在可以通過重構減少的復雜性?
  • Is the code well organized in a package structure which makes sense?

    代碼是否合理地以有意義的包結構進行了組織?
  • Are the class names intuitive and is it obvious what they do?

    類名是直觀的,并且它們的作用很明顯嗎?
  • Are there any classes which are notably large?

    有沒有特別大的課程?
  • Are there any particularly long methods?

    有沒有特別長的方法?
  • Do all the method names seem clear and intuitive?

    所有方法名稱看起來清晰直觀嗎?
  • Is the code well documented?

    該代碼是否有據可查?
  • Is the code well tested?

    代碼是否經過良好測試?
  • Are there ways in which this code could be made more efficient?

    有什么方法可以使此代碼更有效?
  • Does the code meet our teams styling standards?

    該代碼是否符合我們團隊的樣式標準?

There are various effective and different code review practices that vary based on team’s needs. So assume this is my personal opinion and that there are other ways that might work for your team. In the end, building such a sensitive process should be subjective to your companies goals, team’s culture and overall R&D structure.

有多種有效且不同的代碼檢查實踐,具體取決于團隊的需求。 因此,假設這是我的個人觀點,并且還有其他一些方法可以為您的團隊工作。 最后,建立這樣一個敏感的流程應該取決于您公司的目標,團隊的文化和整體研發結構。

If you have any questions or feedback for improving these guidelines, please feel free to add a comment below!

如果您對改善這些準則有任何疑問或反饋,請隨時在下面添加評論!

翻譯自: https://www.freecodecamp.org/news/code-review-the-ultimate-guide-aa45c358bbf5/

審查指南 最新版本

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391950.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391950.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391950.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

非對稱加密

2019獨角獸企業重金招聘Python工程師標準>>> 概念 非對稱加密算法需要兩個密鑰:公鑰(publickey)和私鑰(privatekey)。公鑰與私鑰是一對,如果用公鑰對數據進行加密,只有用對應的私…

管理Sass項目文件結構

http://www.w3cplus.com/preprocessor/architecture-sass-project.html 編輯推薦: 掘金是一個高質量的技術社區,從 CSS 到 Vue.js,性能優化到開源類庫,讓你不錯過前端開發的每一個技術干貨。 點擊鏈接查看最新前端內容&#xff0c…

Spring—注解開發

Spring原始注解 Spring是輕代碼而重配置的框架,配置比較繁重,影響開發效率,所以注解開發是一種趨勢,注解代替xml配置文 件可以簡化配置,提高開發效率。 Component 使用在類上用于實例化BeanController 使用在web層類…

政府公開數據可視化_公開演講如何幫助您設計更好的數據可視化

政府公開數據可視化What do good speeches and good data visualisation have in common? More than you may think.好的演講和好的數據可視化有什么共同點? 超出您的想象。 Aristotle — the founding father of all things public speaking — believed that th…

C++字符串完全指引之一 —— Win32 字符編碼 (轉載)

C字符串完全指引之一 —— Win32 字符編碼原著:Michael Dunn翻譯:Chengjie Sun 原文出處:CodeProject:The Complete Guide to C Strings, Part I 引言  毫無疑問,我們都看到過像 TCHAR, std::string, BSTR 等各種各樣…

網絡計算機無法訪問 請檢查,局域網電腦無法訪問,請檢查來賓訪問帳號是否開通...

局域網電腦無法訪問,有時候并不是由于網絡故障引起的,而是因為自身電腦的一些設置問題,例如之前談過的網絡參數設置不對造成局域網電腦無法訪問。今天分析另一個電腦設置的因素,它也會導致局域網電腦無法訪問,那就是賓…

unity中創建游戲場景_在Unity中創建Beat Em Up游戲

unity中創建游戲場景Learn how to use Unity to create a 3D Beat Em Up game in this full tutorial from Awesome Tuts. 在Awesome Tuts的完整教程中,了解如何使用Unity來創建3D Beat Em Up游戲。 This tutorial covers everything you need to know to make a …

雷軍的金山云D輪獲3億美元!投后估值達19億美金

12月12日,雷軍旗下金山云宣布D輪完成3億美元融資,金額為云行業單輪融資最高。至此金山云投后估值達到19億美元,成為國內估值最高的獨立云服務商。金山集團相關公告顯示,金山云在本輪融資中總計發行3.535億股D系列優先股。驪悅投資…

轉:利用深度學習方法進行情感分析以及在海航輿情云平臺的實踐

http://geek.csdn.net/news/detail/139152 本文主要為大家介紹深度學習算法在自然語言處理任務中的應用——包括算法的原理是什么,相比于其他算法它具有什么優勢,以及如何使用深度學習算法進行情感分析。 原理解析 在講算法之前,我們需要先剖…

消費者行為分析_消費者行為分析-是否點擊廣告?

消費者行為分析什么是消費者行為? (What is Consumer Behavior?) consumer behavior is the study of individuals, groups, or organizations and all the activities associated with the purchase, use, and disposal of goods and services, and how the consu…

Spring—集成Junit

Spring集成Junit步驟 ①導入spring集成Junit的坐標 ②使用Runwith注解替換原來的運行期 ③使用ContextCon?guration指定配置文件或配置類 ④使用Autowired注入需要測試的對象 ⑤創建測試方法進行測試 ①導入spring集成Junit的坐標 <dependency> <groupId>org.s…

計算機的微程序存放在dram,計算機組成與結構

計算機組成與結構A/B卷填空1. 原碼一位乘法中&#xff0c;符號位與數值位(分開計算)&#xff0c;運算結果的符號位等于(相乘兩數符號位的異或值)。2. 微程序&#xff0c;微指令只存放在只讀存儲器中。3. 輔助磁道被分為若干個扇區4. 總線數據傳輸方式&#xff1a;_串行_,_并行_…

python算法面試_求職面試的Python算法

python算法面試During software job interviews, candidates often have to solve algorithm challenges. In this video from CupOfCode01, you will learn about common algorithm concepts in Python and how to solve algorithm challenges you may encounter in an interv…

vue實用難點講解

此篇文章是我基于研究vue文檔三遍的基礎上&#xff0c;覺得還有點難理解或者難記的知識點總結 列表渲染 1.渲染組件必須加key&#xff0c;并且屬性是手動傳遞給組件的<my-componentv-for"(item, index) in items"v-bind:item"item"v-bind:index"in…

leetcode 1208. 盡可能使字符串相等(滑動窗口)

給你兩個長度相同的字符串&#xff0c;s 和 t。 將 s 中的第 i 個字符變到 t 中的第 i 個字符需要 |s[i] - t[i]| 的開銷&#xff08;開銷可能為 0&#xff09;&#xff0c;也就是兩個字符的 ASCII 碼值的差的絕對值。 用于變更字符串的最大預算是 maxCost。在轉化字符串時&a…

魅族mx5游戲模式小熊貓_您不知道的5大熊貓技巧

魅族mx5游戲模式小熊貓重點 (Top highlight)I’ve been using pandas for years and each time I feel I am typing too much, I google it and I usually find a new pandas trick! I learned about these functions recently and I deem them essential because of ease of u…

可行性分析報告

1 引言1.1 編寫目的&#xff1a;闡明編寫可行性研究報告的目的&#xff0c;提出讀者對象。1.2 項目背景&#xff1a;應包括● 所建議開發軟件的名稱● 項目的任務提出者、開發者、用戶及實現軟件的單位● 項目與其他軟件或其他系統的關系。1.3 定義&#xff1a;列出文檔中用到的…

(Python的)__ name__中包含什么?

_名稱_變量及其在Python中的用法簡介 (An introduction to the _ _name_ _ variable and its usage in Python) You’ve most likely seen the __name__ variable when you’ve gone through Python code. Below you see an example code snippet of how it may look:通過Pytho…

畢業論文計算機附錄模板,畢業論文格式是什么,附錄又是什么?

畢業論文格式是什么&#xff0c;附錄又是什么?附錄對論文內用起到一個補充說明的作用&#xff0c;附錄應屬于論文的正文&#xff0c;有的論文需要寫明&#xff0c;有的論文可能不需要寫&#xff0c;大多數情況是不需要寫的&#xff0c;附錄的位置一般放在論文的結尾處&#xf…

文件上傳速度查詢方法

由于業務遷移&#xff0c;需要將大量文件拷貝到目標機器上的/mnt目錄&#xff0c;在拷貝過程中&#xff0c;想要查看上傳的速度&#xff0c;做法如下&#xff1a;[rootmail01 ~]# du -sh /mnt5.6G /mnt[rootmail01 ~]# watch -n1 du -sm /mnt/ #會出現下面的一屏現象 …