代码走查和代码审查_如何避免代码审查陷阱降低生产率
代碼走查和代碼審查
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.
代碼審查是許多高性能團(tuán)隊(duì)使用的一種工程實(shí)踐。 盡管這種軟件實(shí)踐有很多優(yōu)點(diǎn),但是進(jìn)行代碼審查的團(tuán)隊(duì)也遇到了很多代碼審查陷阱。
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.
在本文中,我將解釋您應(yīng)注意的主要代碼審查陷阱,以確保代碼審查不會(huì)使您的團(tuán)隊(duì)減速。 了解哪些陷阱和問題會(huì)幫助您確保產(chǎn)生高效的代碼審查經(jīng)驗(yàn)。 這些發(fā)現(xiàn)是基于我們?cè)贛icrosoft進(jìn)行的一項(xiàng)針對(duì)900多名參與者的調(diào)查得出的。
典型的代碼審查過程 (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.
典型的基于工具的代碼審查過程大致如下:開發(fā)人員完成一段代碼后,便準(zhǔn)備要提交以供審查的代碼。 然后,他們選擇被通知有關(guān)評(píng)論的評(píng)論者。 然后,審閱者審閱代碼并發(fā)表評(píng)論。 代碼的作者處理這些注釋,并相應(yīng)地改進(jìn)和更改代碼。 一旦每個(gè)人都滿意或達(dá)成協(xié)議,就可以將代碼檢入代碼庫(kù)。
In another post, I described how a typical code review process looks like at Microsoft.
在另一篇文章中,我描述了典型的代碼審查過程在Microsoft的情況。
代碼審查并不總是一個(gè)平穩(wěn)的過程 (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.
這些步驟讀起來很順利。 但是,實(shí)際上,就像一切一樣,事情往往比預(yù)期的要復(fù)雜。 在代碼審查過程中,有很多陷阱可以減少整個(gè)團(tuán)隊(duì)進(jìn)行代碼審查的積極經(jīng)驗(yàn)。 如果執(zhí)行不正確,代碼審查也可能會(huì)損害整個(gè)團(tuán)隊(duì)的工作效率。 因此,讓我們看一下代碼審查的困難和陷阱。
The two main types of code review pitfalls are about the time spent on code reviews, and the value code reviews provide.
代碼審查陷阱的兩種主要類型是代碼審查所花費(fèi)的時(shí)間以及代碼審查所提供的價(jià)值。
Be aware of code review pitfalls. Otherwise, code reviews can slow your team down. Click To Tweet
注意代碼審查的陷阱。 否則,代碼審查會(huì)拖慢您的團(tuán)隊(duì)。 點(diǎn)擊鳴叫
等待代碼審查反饋很痛苦 (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.
代碼作者面臨的主要陷阱之一是及時(shí)接收反饋。 等待注釋進(jìn)入而無法同時(shí)在代碼上工作可能是一個(gè)巨大的問題。 即使開發(fā)人員可以承擔(dān)其他工作,但如果代碼審查花費(fèi)的時(shí)間太長(zhǎng),則會(huì)影響開發(fā)人員的工作效率以及開發(fā)人員的滿意度。
But, why does the code review feedback take so long?
但是,為什么代碼審查反饋需要這么長(zhǎng)時(shí)間?
開發(fā)人員必須兼顧多項(xiàng)責(zé)任 (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.
嗯,代碼審查不是代碼審查者必須執(zhí)行的唯一任務(wù)。 相反,即使開發(fā)人員的日常工作可能要花費(fèi)大量時(shí)間,代碼審查也只是開發(fā)人員職責(zé)和任務(wù)的一部分。 因此,代碼審查者很可能從事其他活動(dòng),并且必須先停止或完成那些活動(dòng),然后再查看代碼審查。
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.
如果時(shí)機(jī)不理想,特別是如果代碼審閱者沒有預(yù)料到會(huì)發(fā)生這種變化,那么很可能需要一段時(shí)間才能查看審閱。 遠(yuǎn)程團(tuán)隊(duì)還必須意識(shí)到時(shí)差。 否則,代碼審查可能甚至需要更長(zhǎng)的時(shí)間。
如果不將代碼審查視為實(shí)際工作,則開發(fā)人員將面臨問題 (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.
時(shí)間限制是真實(shí)的,并且會(huì)影響代碼審閱者和代碼作者。 進(jìn)行正確的代碼審查需要時(shí)間。 如果團(tuán)隊(duì)希望開發(fā)人員進(jìn)行代碼審查,但不重視或不考慮開發(fā)人員花費(fèi)在代碼審查上的時(shí)間,那么這將成為一個(gè)真正的問題。
You can’t expect quality code reviews if you don’t value the time a developer spends on them. Click To Tweet
如果您不重視開發(fā)人員在代碼審查上花費(fèi)的時(shí)間,就無法期望獲得高質(zhì)量的代碼審查。 點(diǎn)擊鳴叫
不獎(jiǎng)勵(lì)代碼審查工作和性能 (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.
如果您不獎(jiǎng)勵(lì)開發(fā)人員在此任務(wù)上花費(fèi)的精力,那么聲稱對(duì)代碼進(jìn)行評(píng)估就無濟(jì)于事。 許多公司專注于獎(jiǎng)勵(lì)開發(fā)人員編寫的代碼量或開發(fā)的功能。 這降低了開發(fā)人員做好彼此幫助的動(dòng)力和能力(包括代碼審查)。 代碼審查工作和績(jī)效應(yīng)成為績(jī)效評(píng)估或升級(jí)決策的基石。
If you want your team to do code reviews well, reward them for their work. Click To Tweet
如果您希望您的團(tuán)隊(duì)對(duì)代碼進(jìn)行良好的審查,則對(duì)他們的工作給予獎(jiǎng)勵(lì)。 點(diǎn)擊鳴叫
社會(huì)因素和團(tuán)隊(duì)動(dòng)力 (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:
但是等待代碼審查并不總是與缺少時(shí)間或缺少獎(jiǎng)勵(lì)系統(tǒng)有關(guān)。 由于其社交性質(zhì),延遲審核可能是由于不安全感或團(tuán)隊(duì)動(dòng)態(tài)所致。 尤其是如果代碼審查不勝枚舉,或者如果審查者是新來的代碼,那么進(jìn)行代碼審查可能會(huì)很麻煩:
I’m expected to participate, but I’m not quite sure how. I’ll wait until someone else starts. — study participant
我預(yù)計(jì)會(huì)參加,但是我不確定如何參加。 我將等到其他人開始。 -研究參與者
大評(píng)論很難復(fù)習(xí) (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?
另一個(gè)重要的代碼審查陷阱是大型審查。 假設(shè)您是審閱者,而您剛剛獲得了此審閱。 您認(rèn)為很好,我很快就去研究一下,但是一旦您打開審閱,您就會(huì)看到這個(gè)巨大的代碼更改。 幾個(gè)文件已更改,所有更改在整個(gè)代碼庫(kù)中都纏在一起。 您的第一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.
那就對(duì)了。 這正是我們?cè)诜治鰯?shù)千個(gè)代碼審查時(shí)所看到的。 評(píng)審時(shí)間不僅隨著代碼大小的變化而增加,而且反饋質(zhì)量也會(huì)下降。 好吧,這可能是可以理解的。
10 lines of code = 10 issues.
10行代碼= 10個(gè)問題。
500 lines of code = “l(fā)ooks fine.”
500行代碼=“看起來不錯(cuò)”。
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.
大型代碼更改非常難以審核。 此外,如果代碼檢查者對(duì)更改所基于的代碼庫(kù)部分不太熟悉,那么檢查很快就會(huì)成為噩夢(mèng)。
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
大代碼審查很難審查。 評(píng)審的質(zhì)量隨著更改的大小而降低,從而限制了價(jià)值團(tuán)隊(duì)從代碼評(píng)審中脫身的價(jià)值。 點(diǎn)擊鳴叫
了解代碼更改需要一些指導(dǎo) (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.
了解代碼更改,尤其是代碼更改的動(dòng)機(jī),是許多審閱者面臨的另一個(gè)代碼審閱陷阱。 如果沒有說明來說明更改的目的,則代碼審查將變得更加困難。 我們?cè)谘芯恐锌吹?#xff0c;如果代碼審閱者不理解代碼更改,或者如果她對(duì)更改量感到不知所措,那么她將無法提供有見地的反饋。
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.
就是這么大的不可理解的混亂。 然后,您將無法添加任何價(jià)值,因?yàn)樗麄冎粫?huì)向您解釋它,而您會(huì)模仿他們的話。
— interviewed developer13
—采訪了developer13
沒有獲得有價(jià)值的反饋會(huì)降低開發(fā)人員從代碼審查中獲得的利益和動(dòng)力 (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.
毫無疑問,將時(shí)間花在代碼審查上并沒有得到有用的反饋是一個(gè)問題。 即使團(tuán)隊(duì)仍然可以從知識(shí)轉(zhuǎn)移中受益,但是當(dāng)開發(fā)人員沒有獲得有價(jià)值的反饋時(shí),他們進(jìn)行代碼審查的動(dòng)機(jī)和代碼審查的好處就會(huì)減少。
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.
審稿人沒有或無法提供有見地的反饋有多種原因。 可能是代碼檢查者沒有適當(dāng)?shù)膶I(yè)知識(shí)。 另一個(gè)常見原因是審閱者沒有足夠的時(shí)間來徹底了解更改。
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.
也許代碼審查者不理解代碼。 也可能是代碼審閱者不知道要查找什么問題。 了解什么能使有價(jià)值的代碼審查反饋有效,并實(shí)施最佳實(shí)踐可以減輕這種陷阱。
一旦主要的討論是關(guān)于樣式,就需要采取行動(dòng) (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.
在代碼審查期間可能發(fā)生的另一個(gè)問題稱為Bikeshedding。 Bikeshedding意味著開發(fā)人員專注于較小的問題,并開始爭(zhēng)論較小的問題,而忽略了嚴(yán)重的問題。
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.
原因是多種多樣的。 導(dǎo)致脫機(jī)的幕后常見挑戰(zhàn)是,開發(fā)人員不了解代碼更改,或者他們沒有足夠的時(shí)間進(jìn)行代碼審查。 有時(shí),騎車流失可能表明團(tuán)隊(duì)動(dòng)力存在問題。
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
如果人們?cè)诖a審查期間對(duì)次要問題提出異議,則必須查看潛在問題。 時(shí)間壓力,太大的評(píng)論,競(jìng)爭(zhēng)? 點(diǎn)擊鳴叫
達(dá)成共識(shí)可能需要面對(duì)面的討論 (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.
有時(shí)可能很難達(dá)成共識(shí)。 這可以在代碼審閱者和代碼作者之間發(fā)生,也可以直接在多個(gè)代碼審閱者之間發(fā)生。 由于團(tuán)隊(duì)動(dòng)態(tài)與這些情況密切相關(guān),因此必須謹(jǐn)慎處理這種情況。 通過工具和書面形式進(jìn)行的交流會(huì)加劇這個(gè)問題。 如果似乎存在任何緊張關(guān)系或有待討論的問題,那么(面對(duì)面或通過視頻通話)面對(duì)面交流是一個(gè)好主意。
代碼審查的好處勝于努力 (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.
我希望這份代碼審查陷阱清單不會(huì)改變您對(duì)代碼審查的看法。 因?yàn)?#xff0c;好消息是,如果您知道代碼審查的陷阱并加以彌補(bǔ),那么代碼審查是一種非常有益的工程技術(shù)。 而且,還有更多行之有效的方式來與代碼審查一起使用。
代碼審查最佳實(shí)踐 (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.
在此代碼審查系列的下一篇博客文章中,我將展示最佳實(shí)踐,以幫助最大程度地減少代碼審查的陷阱和挑戰(zhàn),并確保您的團(tuán)隊(duì)從代碼審查實(shí)踐中獲得最大的收益。 因此,請(qǐng)繼續(xù)閱讀。 要在我發(fā)布下一篇文章時(shí)得到通知,請(qǐng)?jiān)赥witter上關(guān)注我。
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.
我為通訊訂閱者準(zhǔn)備了獨(dú)家的Code Review電子書。 因此,請(qǐng)確保您已訂閱我的電子郵件列表,并確保您的《代碼審查》電子書安全,其中包括一份方便的代碼審查最佳實(shí)踐速查表。
Originally published at https://www.michaelagreiler.com on April 6, 2019.
最初于2019年4月6日發(fā)布在https://www.michaelagreiler.com 。
翻譯自: https://www.freecodecamp.org/news/how-to-avoid-code-review-pitfalls-that-slow-your-productivity-down-b7a8536c4d3b/
代碼走查和代碼審查
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的代码走查和代码审查_如何避免代码审查陷阱降低生产率的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信开发者平台如何编写代码_编写超级清晰
- 下一篇: 梦到房倒屋塌什么预兆