代碼走查和代碼審查_如何避免代碼審查陷阱降低生產率

代碼走查和代碼審查

Code reviewing is an engineering practice used by many high performing teams. And even though this software practice has many advantages, teams doing code reviews also encounter quite a few code review pitfalls.

代碼審查是許多高性能團隊使用的一種工程實踐。 盡管這種軟件實踐有很多優點,但是進行代碼審查的團隊也遇到了很多代碼審查陷阱。

In this article, I explain the main code review pitfalls you should be aware of to ensure code reviewing does not slow your team down. Knowing which pitfalls and problems arise can help you to ensure a productive and effective code review experience. Those findings are based on a survey we conducted at Microsoft with over 900 participants.

在本文中,我將解釋您應注意的主要代碼審查陷阱,以確保代碼審查不會使您的團隊減速。 了解哪些陷阱和問題會幫助您確保產生高效的代碼審查經驗。 這些發現是基于我們在Microsoft進行的一項針對900多名參與者的調查得出的。

典型的代碼審查過程 (A typical code review process)

A typical tool-based code review process looks roughly like this: Once the developer has finished a piece of code, they prepare the code for being submitted for review. Then, they select reviewers who are notified about the review. The reviewers then review the code and give comments. The author of the code works on those comments and improves and changes the code accordingly. Once everybody is satisfied, or an agreement is reached, the code can be checked into the code base.

典型的基于工具的代碼審查過程大致如下:開發人員完成一段代碼后,便準備要提交以供審查的代碼。 然后,他們選擇被通知有關評論的評論者。 然后,審閱者審閱代碼并發表評論。 代碼的作者處理這些注釋,并相應地改進和更改代碼。 一旦每個人都滿意或達成協議,就可以將代碼檢入代碼庫。

In another post, I described how a typical code review process looks like at Microsoft.

在另一篇文章中,我描述了典型的代碼審查過程在Microsoft的情況。

代碼審查并不總是一個平穩的過程 (Code reviewing isn’t always a smooth process)

These steps read like a smooth process. But, like everything, in practice, things tend to be more complicated than anticipated. During the code review process there a quite a few pitfalls that can reduce the positive experience with code reviews for the whole team. If not done correctly, code reviewing can also take its tolls on the whole team’s productivity. So, let’s have a look at the difficulties and pitfalls of code reviews.

這些步驟讀起來很順利。 但是,實際上,就像一切一樣,事情往往比預期的要復雜。 在代碼審查過程中,有很多陷阱可以減少整個團隊進行代碼審查的積極經驗。 如果執行不正確,代碼審查也可能會損害整個團隊的工作效率。 因此,讓我們看一下代碼審查的困難和陷阱。

The two main types of code review pitfalls are about the time spent on code reviews, and the value code reviews provide.

代碼審查陷阱的兩種主要類型是代碼審查所花費的時間以及代碼審查所提供的價值。

Be aware of code review pitfalls. Otherwise, code reviews can slow your team down. Click To Tweet

注意代碼審查的陷阱。 否則,代碼審查會拖慢您的團隊。 點擊鳴叫

等待代碼審查反饋很痛苦 (Waiting for code review feedback is a pain)

One of the main pitfalls code authors face is to receive feedback in a timely manner. Waiting for the comments to come in and not being able to work on the code in the meanwhile can be a huge problem. Even though developers can pick up other tasks to work on, if the code review takes too long, it impacts the developer’s productivity and also the developer’s satisfaction.

代碼作者面臨的主要陷阱之一是及時接收反饋。 等待注釋進入而無法同時在代碼上工作可能是一個巨大的問題。 即使開發人員可以承擔其他工作,但如果代碼審查花費的時間太長,則會影響開發人員的工作效率以及開發人員的滿意度。

But, why does the code review feedback take so long?

但是,為什么代碼審查反饋需要這么長時間?

開發人員必須兼顧多項責任 (Developers have to juggle several responsibilities)

Well, code reviewing is not the only task the code reviewer has to perform. On the contrary, code reviewing — even though it can take a significant amount of time of a developer’s day-to-day work — is only one part of the responsibilities and tasks of a developer. So, it is very likely that the code reviewer is engaged in other activities and has to stop or finish those first before looking at the code review.

嗯,代碼審查不是代碼審查者必須執行的唯一任務。 相反,即使開發人員的日常工作可能要花費大量時間,代碼審查也只是開發人員職責和任務的一部分。 因此,代碼審查者很可能從事其他活動,并且必須先停止或完成那些活動,然后再查看代碼審查。

If the timing is not ideal, and especially if the code reviewer hasn’t anticipated this change coming along, chances are, it takes a while before they look at the review. Remote teams also have to be aware of time differences. Otherwise, code reviews might even take longer.

如果時機不理想,特別是如果代碼審閱者沒有預料到會發生這種變化,那么很可能需要一段時間才能查看審閱。 遠程團隊還必須意識到時差。 否則,代碼審查可能甚至需要更長的時間。

如果不將代碼審查視為實際工作,則開發人員將面臨問題 (Developers face problems if code reviews are not counted as actual work)

Time constraints are real, and they affect both, the code reviewer and the author of the code. Doing a proper code review takes time. If teams want developers to do code reviews but do not value or count the time developers spend on code reviews, this becomes a real problem.

時間限制是真實的,并且會影響代碼審閱者和代碼作者。 進行正確的代碼審查需要時間。 如果團隊希望開發人員進行代碼審查,但不重視或不考慮開發人員花費在代碼審查上的時間,那么這將成為一個真正的問題。

You can’t expect quality code reviews if you don’t value the time a developer spends on them. Click To Tweet

如果您不重視開發人員在代碼審查上花費的時間,就無法期望獲得高質量的代碼審查。 點擊鳴叫

不獎勵代碼審查工作和性能 (Not rewarding code reviewing efforts and performance)

It does not help to claim to value code reviews if you do not reward the effort developers spend on this task. Many companies focus on rewarding developers for the amount of code they write or the features they develop. This decreases the motivation and the ability of developers to do a good job helping each other (which includes code reviewing). Code review effort and performance should be a cornerstone for performance evaluation or promotion decisions.

如果您不獎勵開發人員在此任務上花費的精力,那么聲稱對代碼進行評估就無濟于事。 許多公司專注于獎勵開發人員編寫的代碼量或開發的功能。 這降低了開發人員做好彼此幫助的動力和能力(包括代碼審查)。 代碼審查工作和績效應成為績效評估或升級決策的基石。

If you want your team to do code reviews well, reward them for their work. Click To Tweet

如果您希望您的團隊對代碼進行良好的審查,則對他們的工作給予獎勵。 點擊鳴叫

社會因素和團隊動力 (Social factors and team dynamics)

But waiting on a code review had not always to do with the lack of time or missing reward system. Due to its social character, delayed reviews can be due to insecurities or team dynamics. Especially if the code review is overwhelming, or if the reviewer is new to the code, doing a code review can be overwhelming:

但是等待代碼審查并不總是與缺少時間或缺少獎勵系統有關。 由于其社交性質,延遲審核可能是由于不安全感或團隊動態所致。 尤其是如果代碼審查不勝枚舉,或者如果審查者是新來的代碼,那么進行代碼審查可能會很麻煩:

I’m expected to participate, but I’m not quite sure how. I’ll wait until someone else starts. — study participant

我預計會參加,但是我不確定如何參加。 我將等到其他人開始。 -研究參與者

大評論很難復習 (Large reviews are hard to review)

Another significant code review pitfall is large reviews. Imagine you are the reviewer, and you just got this review. You think, well, I am quickly going to look at that, but once you open the review, you see this large code change. Several files have been changed, and all changes tangle throughout the code base. What’s your first reaction?

另一個重要的代碼審查陷阱是大型審查。 假設您是審閱者,而您剛剛獲得了此審閱。 您認為很好,我很快就去研究一下,但是一旦您打開審閱,您就會看到這個巨大的代碼更改。 幾個文件已更改,所有更改在整個代碼庫中都纏在一起。 您的第一React是什么?

Probably: holy cow!

可能是:圣牛!

That’s right. That is exactly what we saw when analyzing thousands of code reviews. Not only does review time increase with the size of the code change, but also feedback quality decreases. Well, that’s probably understandable.

那就對了。 這正是我們在分析數千個代碼審查時所看到的。 評審時間不僅隨著代碼大小的變化而增加,而且反饋質量也會下降。 好吧,這可能是可以理解的。

10 lines of code = 10 issues.

10行代碼= 10個問題。

500 lines of code = “looks fine.”

500行代碼=“看起來不錯”。

Code reviews.

代碼審查。

— I Am Devloper (@iamdevloper) November 5, 2013

— I Am Devloper(@iamdevloper) 2013年11月5日

Large code changes are just incredibly difficult to review. If, in addition, the code reviewer is not that familiar with the part of the code base the change took place in, reviewing can quickly become a nightmare.

大型代碼更改非常難以審核。 此外,如果代碼檢查者對更改所基于的代碼庫部分不太熟悉,那么檢查很快就會成為噩夢。

Large code reviews are hard to review. The quality of the review decreases with the size of the change, thus limiting the value teams get out of from code reviews. Click To Tweet

大代碼審查很難審查。 評審的質量隨著更改的大小而降低,從而限制了價值團隊從代碼評審中脫身的價值。 點擊鳴叫

了解代碼更改需要一些指導 (Understanding code changes needs some guidance)

Understanding code changes, and especially the motivation for a code change, is another code review pitfall many reviewers face. If there is no description explaining the purpose of the change, code reviewing becomes much harder. We saw in the study that if the code reviewer does not understand the code change, or if she is overwhelmed by the amount of change, she cannot give insightful feedback.

了解代碼更改,尤其是代碼更改的動機,是許多審閱者面臨的另一個代碼審閱陷阱。 如果沒有說明來說明更改的目的,則代碼審查將變得更加困難。 我們在研究中看到,如果代碼審閱者不理解代碼更改,或者如果她對更改量感到不知所措,那么她將無法提供有見地的反饋。

It’s just this big incomprehensible mess. Then you can’t add any value because they are just going to explain it to you and you’re going to parrot back what they say.

就是這么大的不可理解的混亂。 然后,您將無法添加任何價值,因為他們只會向您解釋它,而您會模仿他們的話。

— interviewed developer13

—采訪了developer13

沒有獲得有價值的反饋會降低開發人員從代碼審查中獲得的利益和動力 (Not getting valuable feedback decreases the developers’ benefit from and motivation for code reviews)

Without doubt, spending the time on code reviews and not getting useful feedback back is a problem. Even though the team might still benefit from the knowledge transfer, the developer’s motivation to do code reviews and the benefits from code reviews decrease when they do not get valuable feedback.

毫無疑問,將時間花在代碼審查上并沒有得到有用的反饋是一個問題。 即使團隊仍然可以從知識轉移中受益,但是當開發人員沒有獲得有價值的反饋時,他們進行代碼審查的動機和代碼審查的好處就會減少。

There are several reasons why reviewers do not or can’t give insightful feedback. It can be that the code reviewer did not have the right expertise. Another common reason is that the reviewer did not have enough time to look thoroughly through the change.

審稿人沒有或無法提供有見地的反饋有多種原因。 可能是代碼檢查者沒有適當的專業知識。 另一個常見原因是審閱者沒有足夠的時間來徹底了解更改。

Maybe the code reviewer does not understand the code. It can also be that the code reviewer does not know what issues to look for. Understanding what makes for valuable code review feedback and implementing best practices mitigates this pitfall.

也許代碼審查者不理解代碼。 也可能是代碼審閱者不知道要查找什么問題。 了解什么能使有價值的代碼審查反饋有效,并實施最佳實踐可以減輕這種陷阱。

一旦主要的討論是關于樣式,就需要采取行動 (Once the main discussion is about styling, you need to act)

Another problem that can happen during a code review is called bikeshedding. Bikeshedding means that developers focus on smaller issues and start disputing minor issues and overlook the serious ones.

在代碼審查期間可能發生的另一個問題稱為Bikeshedding。 Bikeshedding意味著開發人員專注于較小的問題,并開始爭論較小的問題,而忽略了嚴重的問題。

The reasons for that are manifold. Common behind the scenes challenges that lead to bikeshedding is that developers do not understand the code change or that they do not have enough time for the code reviews. Sometimes bikeshedding can be a sign that there are issues with the team dynamics.

原因是多種多樣的。 導致脫機的幕后常見挑戰是,開發人員不了解代碼更改,或者他們沒有足夠的時間進行代碼審查。 有時,騎車流失可能表明團隊動力存在問題。

If people dispute about minor issues during code reviews, you have to take a look at the underlying issue. Time pressure, too large reviews, rivalry? Click To Tweet

如果人們在代碼審查期間對次要問題提出異議,則必須查看潛在問題。 時間壓力,太大的評論,競爭? 點擊鳴叫

達成共識可能需要面對面的討論 (Reaching consensus might need a face-to-face discussion)

Sometimes it can happen that it is hard to reach a consensus. This can occur between code reviewer and code author, or also between several code reviewers directly. Such situations must be handled carefully as team dynamics are closely connected to these happenings. Communication via tools and in written form can aggravate this problem. If there seems to be any tension, or contentious issues to discuss, switching to face-to-face (either in person or via a video call) might be a good idea.

有時可能很難達成共識。 這可以在代碼審閱者和代碼作者之間發生,也可以直接在多個代碼審閱者之間發生。 由于團隊動態與這些情況密切相關,因此必須謹慎處理這種情況。 通過工具和書面形式進行的交流會加劇這個問題。 如果似乎存在任何緊張關系或有待討論的問題,那么(面對面或通過視頻通話)面對面交流是一個好主意。

代碼審查的好處勝于努力 (The benefits of code review outweigh the effort)

I hope this list of code review pitfalls did not change your mind about code reviews. Because, the good news is that if you are aware of the code review pitfalls and counteract them, code reviews are a very beneficial engineering technique. And, there are even more proven ways to work effectively with code reviews.

我希望這份代碼審查陷阱清單不會改變您對代碼審查的看法。 因為,好消息是,如果您知道代碼審查的陷阱并加以彌補,那么代碼審查是一種非常有益的工程技術。 而且,還有更多行之有效的方式來與代碼審查一起使用。

代碼審查最佳實踐 (Code review best practices)

In the next blog post in this code review series, I show best practices to help to minimize the code review pitfalls and challenges and ensure your team gets the best out of the code review practice. So keep on reading. To be notified when I publish the next post, follow me on twitter.

在此代碼審查系列的下一篇博客文章中,我將展示最佳實踐,以幫助最大程度地減少代碼審查的陷阱和挑戰,并確保您的團隊從代碼審查實踐中獲得最大的收益。 因此,請繼續閱讀。 要在我發布下一篇文章時得到通知,請在Twitter上關注我。

I prepared an exclusive Code Review e-Book for my newsletter subscribers. So make sure you subscribe to my email list and secure your Code Review e-Book including a handy cheat sheet of code review best practices.

我為通訊訂閱者準備了獨家的Code Review電子書。 因此,請確保您已訂閱我的電子郵件列表,并確保您的《代碼審查》電子書安全,其中包括一份方便的代碼審查最佳實踐速查表。

Originally published at https://www.michaelagreiler.com on April 6, 2019.

最初于2019年4月6日發布在https://www.michaelagreiler.com 。

翻譯自: https://www.freecodecamp.org/news/how-to-avoid-code-review-pitfalls-that-slow-your-productivity-down-b7a8536c4d3b/

代碼走查和代碼審查

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

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

相關文章

Zabbix3.2安裝

一、環境 OS: CentOS7.0.1406 Zabbix版本: Zabbix-3.2 下載地址: http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm MySQL版本: 5.6.37 MySQL: http://repo.mysql.com/mysql-community-release-el7-5.noarch.r…

Warensoft Unity3D通信庫使用向導4-SQL SERVER訪問組件使用說明

Warensoft Unity3D通信庫使用向導4-SQL SERVER訪問組件使用說明 (作者:warensoft,有問題請聯系warensoft163.com) 在前一節《warensoft unity3d通信庫使用向導3-建立WarensoftDataService》中已經說明如何配置Warensoft Data Service,從本節開始,將說明…

01-gt;選中UITableViewCell后,Cell中的UILabel的背景顏色變成透明色

解決方案有兩種方法一 -> 新建一個UILabel類, 繼承UILabel, 然后重寫 setBackgroundColor: 方法, 在這個方法里不做任何操作, 讓UILabel的backgroundColor不發生改變.寫在最后, 感謝參考的出處:不是謝志偉StackOverflow: UITableViewCell makes labels background clear whe…

leetcode 703. 數據流中的第 K 大元素(堆)

設計一個找到數據流中第 k 大元素的類(class)。注意是排序后的第 k 大元素,不是第 k 個不同的元素。 請實現 KthLargest 類: KthLargest(int k, int[] nums) 使用整數 k 和整數流 nums 初始化對象。 int add(int val) 將 val 插…

不知道輸入何時停止_知道何時停止

不知道輸入何時停止In predictive analytics, it can be a tricky thing to know when to stop.在預測分析中,知道何時停止可能是一件棘手的事情。 Unlike many of life’s activities, there’s no definitive finishing line, after which you can say “tick, I…

移動認證_如何在移動設備上實施安全的生物特征認證

移動認證by Kathy Dinh凱西丁(Kathy Dinh) 如何在移動設備上實施安全的生物特征認證 (How to implement secure Biometric Authentication on mobile devices) A quick search for React Native biometric authentication would give you several tutorials. That was the fir…

[Luogu1890]gcd區間

原題鏈接https://www.luogu.org/problem/show?pid1890 暴力中的暴力。 對于每一組詢問l..r,我們先循環暴力枚舉l..r中最大值到1,再暴力循環l..r的每一個數,判斷前一重循環能否整除后一重,如果全部都能,則可判定它就是…

Android Studio自定義模板 做開發竟然可以如此輕松 后篇

###1.概述 最近有很多人反饋,有些哥們不喜歡看文字性的東西,還有一些哥們根本就不知道我在搞啥子,那么以后我就采用博客加視頻的方式,我們可以選擇看視頻講解:http://pan.baidu.com/s/1i5uh2uD   內涵段子項目資料及…

ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.

ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. 解決方案: 異步更新(建議使用)強制進行變更檢測,但是會觸發子組件的變更檢測,再次導致父組件屬性改變Parent.Component.…

leetcode 119. 楊輝三角 II

給定一個非負索引 k,其中 k ≤ 33,返回楊輝三角的第 k 行。 在楊輝三角中,每個數是它左上方和右上方的數的和。 示例: 輸入: 3 輸出: [1,3,3,1] 解題思路 因為楊輝三角的下層由上一層決定,所以只需要保存上一層的元素&#x…

掌握大數據數據分析師嗎?_要掌握您的數據嗎? 這就是為什么您應該關心元數據的原因...

掌握大數據數據分析師嗎?Either you are a data scientist, a data engineer, or someone enthusiastic about data, understanding your data is one thing you don’t want to overlook. We usually regard data as numbers, texts, or images, but data is more than that.…

react 使用 mobx_如何使用React和MobX狀態樹構建基于狀態的路由器

react 使用 mobxby Miles Till由Miles Till 如何使用React和MobX狀態樹構建基于狀態的路由器 (How to build a state-based router using React and MobX State Tree) Introducing mobx-state-tree-routerMobx狀態樹路由器簡介 If you want to skip ahead to the finished ex…

docker在Centos上的安裝

Centos6安裝docker 系統:centos6.5 內核:3.10.107-1(已升級),docker對RHEL/Centos的最低內核支持是2.6.32-431,epel源的docker版本推薦內核為3.10版本。 內核升級可參考:https://www.jslink.org/linux/centos-kernel-u…

Lambda表達式的前世今生

Lambda 表達式 早在 C# 1.0 時,C#中就引入了委托(delegate)類型的概念。通過使用這個類型,我們可以將函數作為參數進行傳遞。在某種意義上,委托可理解為一種托管的強類型的函數指針。 通常情況下,使用委托來…

matplotlib柱狀圖、面積圖、直方圖、散點圖、極坐標圖、箱型圖

一、柱狀圖 1.通過obj.plot() 柱狀圖用bar表示,可通過obj.plot(kindbar)或者obj.plot.bar()生成;在柱狀圖中添加參數stackedTrue,會形成堆疊圖。 fig,axes plt.subplots(2,2,figsize(10,6)) s pd.Series(np.random.randint(0,10,15),index …

微信支付商業版 結算周期_了解商業周期

微信支付商業版 結算周期Economics is an inexact science, finance and investing even more so (some would call them art). But if there’s one thing in economics that you can consistently count on over the long run, it’s the tendency of things to mean revert …

leetcode 448. 找到所有數組中消失的數字

給定一個范圍在 1 ≤ a[i] ≤ n ( n 數組大小 ) 的 整型數組,數組中的元素一些出現了兩次,另一些只出現一次。 找到所有在 [1, n] 范圍之間沒有出現在數組中的數字。 您能在不使用額外空間且時間復雜度為O(n)的情況下完成這個任務嗎? 你可以假定返回…

前端初學者開發學習視頻_初學者學習前端開發的實用指南

前端初學者開發學習視頻by Nikita Rudenko通過尼基塔魯登科(Nikita Rudenko) 初學者學習前端開發的實用指南 (A practical guide to learning front end development for beginners) I started my coding journey in spring 2018, a bit less than one year ago. I earned som…

weblogic啟動失敗案例(root啟動引起的權限問題)

weblogic的一個domain啟動失敗,在日志中有如下信息提示: **************************************************** To start WebLogic Server, use a username and ** password assigned to an admin-level user. For ** server administration, us…

HTTP請求示例

HTTP請求格式當瀏覽器向Web服務器發出請求時,它向服務器傳遞了一個數據塊,也就是請求信息,HTTP請求信息由3部分組成:l 請求方法URI協議/版本l 請求頭(Request Header)l 請求正文下面是一個HTTP請求的例子:GET/sa…