close

前言

怎麼樣看code的品質或好壞,
通常程式碼複雜度也是其中一個頗重要的因子。

但不完全代表,
複雜度低,就是品質好或好維護的 Code。複雜度高,就是代表品質不好或可讀性低的 Code。

但是,複雜度還是可以像健康檢查一樣,反應出程式裡面是否有哪裡可能有問題。

Visual Stuido 裡面也有『計算程式碼度量』的功能,
不過今天要介紹的 SourceMonitor,是免費的,而且支援的語言比較多,
也比較不需要為了測量複雜度,而去安裝 Visuual Studio 這麼大的工具。

 

介紹

SourceMonitor 下載網址:http://www.campwoodsw.com/sourcemonitor.html

Features介紹:

  • Collects metrics in a fast, single pass through source files.
  • Measures metrics for source code written in C++, C, C#, VB.NET, Java, Delphi, Visual Basic (VB6) or HTML.
  • Includes method and function level metrics for C++, C, C#, VB.NET, Java, and Delphi.
  • Saves metrics in checkpoints for comparison during software development projects.
  • Displays and prints metrics in tables and charts.
  • Operates within a standard Windows GUI or inside your scripts using XML command files.
  • Exports metrics to XML or CSV (comma-separated-value) files for further processing with other tools.

Size:安裝完在C槽佔3.81MB。

可搭配 SubVersion 跟 Continue Integration Server 一起運作,當 SubVersion 有更新時,自動掃瞄最新的程式碼,產出 Report。

產出結果可參考:http://www.gss.com.tw/tw/eispage/vol57/eispage5708.htm

而 SourceMonitor 採用的複雜度是 cyclomatic complexity,主要是針對每一個 Method 裡所有可能執行的路徑來定義複雜度。
也就是 if、for、while、and、or、else 等有判斷邏輯導致路徑分歧,都會增加複雜度。

以人的角度來看,就是腦袋需要更多的空間來暫存可能會跑那些情況。(也就是 SourceMonitor 所定義的『複雜』)

詳細內容:http://www.dotblogs.com.tw/hatelove/archive/2010/02/10/sourcemonitor.aspx

內容轉自:In91點部落

arrow
arrow
    全站熱搜

    mming 發表在 痞客邦 留言(0) 人氣()