程式碼檢閱的最佳實務

來源:互聯網
上載者:User
        沒有人否認code review(程式碼檢閱、複查) 對提高代碼品質的作用,但是如何進行code review? 這裡 確實存在一些方法和技巧。方法不當,會浪費大量時間、造成低效率;流程過緊,會大大降低生產力,流程過松,很難知道code review的效果,甚至有沒有進行code review,都很難判斷。

這裡有11條代碼複審的最佳實務:

  1. 一次檢查少於200~400行代碼
  2. 努力達到一個合適的檢查速度:每小時少於300~500行代碼
  3. 有足夠的時間、以適當的速度、仔細地檢查,但不宜超過60~90分鐘
  4. 在複審前,代碼作者應該對代碼進行注釋
  5. 建立量化的目標並獲得相關的指標資料,從而不斷改進流程
  6. 使用檢查表(checklist)肯定能改進雙方(作者和複審者)的結果
  7. 驗證缺陷是否真正被修複
  8. 管理員要營造良好的氛圍(文化),使大家可以積極地對待缺陷的發現,發現足夠多的缺陷,只關心問題是什麼、怎樣引起的,而不關心是誰寫的代碼
  9. 清楚度量工具("Big Brother")的作用——度量工具是雙刃劍,要小心使用
  10. 自我約束:即使沒有時間完成所有代碼的檢查,也應該儘可能去做,哪怕是一部分
  11. 輕量級的code review是高效率的、可行的,並能有效地發現缺陷
 


詳細內容參見 [PDF] Best Practices for Peer Code Review  ( www.SmartBearSoftware.com)
或 Code Reviews - http://dotnet.org.za/cjlotz/archive/2007/08/28/code-reviews.aspx

有一個評論,對大家也有協助,如強調code review的目標、代碼靜態分析工具的使用等:

I think the first thing you need to figure out is what kind of errors are you expecting to find during inspections. It must exist a clear idea of the goal of the review and all participants should share this idea. If this is not defined you may have reviews wasting time in discussions about variable names, indentation, code comments, message descriptions, or any other topic.

In my company for example, we don't look for code conventions compliance, we use automated tools to ensure that. We run static analysis tool on our code before inspections, therefore we don't look for the type of errors that this tool can easily report. But we do look for compliance with the design: is the code implementing the defined design appropriately? Are all exception conditions handled following the design?

One useful thing that I did in the past to define our goal for code reviews is to read different code inspection checklists available online and identify the items that I considered useful for our reviews. Then, based on that list I agreed with the team the aspects that we should check in our code reviews. In that way we focused our effort and everyone was on the same page during the review.


另外參考文章:

  • 軟體品質保證的最佳實務之一:Code review和Case review
  • Bug分析:為bug預防奠定基礎
  • extreme inspections:  http://www.gilb.com/community/tiki-page.php?pageName=Inspection
  • http://www.gilb.com/community/tiki-download_file.php?fileId=64


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.