For faster navigation, this Iframe is preloading the Wikiwand page for 代码审查.

代码审查

代碼審查是指對電腦源代码系統化地审查,常用軟體同行評審的方式進行,其目的是在找出及修正在軟體開發初期未發現的錯誤,提升软件质量及開發者的技術。代碼審查常以不同的形式進行,例如结对编程、非正式的看過整個程式碼,或是正式的軟件檢查[1]

簡介

[编辑]

藉由代碼審查可以找到及移除像是格式化字串攻擊英语Format string attacks競爭危害内存泄漏缓存溢出计算机安全隐患,因此提昇代碼的安全性。基於Subversion(可能是Trac或是Redmine)、MercurialGit或其他軟體的線上軟體庫可以允許協同審查代碼,而且有些協同代碼審查工具可以簡化代碼審查的過程。

自動化代碼審查軟體英语code reviewing software可以系統化的檢查源代碼中是否有已知的计算机安全隐患,可以減少大量代碼審查的工作。

卡珀斯·瓊斯(Capers Jones)分析了超過12,000個軟件開發項目,其中使用正式代碼審查的項目,潛在缺陷發現率約在60-65%之間,若是非正式的代碼審查,潛在缺陷發現率不到50%。大部份的測試,潛在缺陷發現率會在30%左右。[2]

一般的代碼審查速度約是一小時150行程式碼,對於一些關鍵的軟體(例如安全关键系統的嵌入式軟體),一小時審查數百行程式碼的審查速度太快,可能無法找到程式中的問題[3][4]。代碼審查一般可以找到及移除約65%的錯誤,最高可以到85%[5]

也有研究針對代碼審查找到的缺陷類型進行分析。代碼審查找到的缺陷中,有75%是和计算机安全隐患有關。對於產品生命週期很長的軟體公司而言,代碼審查是很有效的工具[6] [7]

分類

[编辑]

代码审查一般會分為三類:正式的代码审查、結對程式設計、以及輕量型的非正式代码审查[1]

正式的代码审查(例如范根检查法)有審慎及仔細的流程,由多位參與者分階段進行。正式的代码审查是傳統审查代码的方式,由軟體開發者參加一連串的會議,一行一行的审查程式碼,一般會使用列印好的源代碼。正式的代码审查可以徹底的找到程式中的缺陷,但需要投入許多的資源。

結對程式設計是兩個程式設計師在一個電腦上共同工作,一個輸入程式,另一個工程師审查他或她所輸入的程式,結對程式設計是在極限編程中常見的開發方式。

輕量型的非正式代码审查需要投入的資源比正式的代码审查要少,一般會是在正常軟體開發流程中同時進行,有時也會將結對程式設計視為輕量型代码审查的一種。

  • Email往返:在代碼登入後,源代碼管理系統自動將代碼郵寄給审查者。
  • 配合輔助工具的代码审查:作者及审查者利用配合代码审查的軟體進行审查。

書籍Best Kept Secrets of Peer Code Review中曾提到有關代码审查的案例研究,這個研究發現輕量型代码审查所找到的缺陷會比正式的代码审查要少,但其速度較快,其成本也較低。

評論

[编辑]

以往正式的代碼審查在審查的準備及進行時都需要投入許多的資源。

代碼分析工具的使用可以協助代碼審查。尤其是一些整合在整合開發環境(IDE)下的工具,可以直接提供程式開發者有關編程標準相容的回饋。

相關條目

[编辑]

參考資料

[编辑]
  1. ^ 1.0 1.1 Kolawa, Adam; Huizinga, Dorota. Automated Defect Prevention: Best Practices in Software Management. Wiley-IEEE Computer Society Press. 2007: 260/426 [2012-04-08]. ISBN 0-470-04212-5. (原始内容存档于2012-04-25). 
  2. ^ Jones, Capers; Christof, Ebert. Embedded Software: Facts, Figures, and Future. IEEE Computer Society. April 2009 [2010-10-05]. 
  3. ^ Ganssle, Jack. A Guide to Code Inspections (PDF). The Ganssle Group. February 2010 [2010-10-05]. (原始内容存档 (PDF)于2018-12-15). 
  4. ^ Kemerer, C.F.; Paulk, M.C. The Impact of Design and Code Reviews on Software Quality: An Empirical Study Based on PSP Data. IEEE Transactions on Software Engineering. July-Aug. 2009 [2012-03-21]. 
  5. ^ Jones, Capers. Measuring Defect Potentials and Defect Removal Efficiency. Crosstalk, The Journal of Defense Software Engineering. June 2008 [2010-10-05]. (原始内容存档于2010-01-11). 
  6. ^ Mantyla, M.V.; Lassenius, C. What Types of Defects Are Really Discovered in Code Reviews? (PDF). IEEE Transactions on Software Engineering. May–June 2009 [2012-03-21]. (原始内容存档 (PDF)于2018-07-21). 
  7. ^ Siy, H.; Votta, L. Does the Modern Code Inspection Have Value?. IEEE Proc. International Conference of Software Maintenance. May–June 2001 [2012-03-21]. 
{{bottomLinkPreText}} {{bottomLinkText}}
代码审查
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?