Understand簡明參考


      Understand全稱為Scientific Toolworks Understand,,是一款源代碼閱讀分析軟件,使用它可以大大提高代碼閱讀效率。此軟件亦有架構分析,代碼評審與度量,生成軟件質量統計與報表等功能。

      官方網站:https://www.scitools.com/features/metrics.php

 

      一.安裝

      傻瓜式安裝,安裝過程中使用算號器生成可用序列號填入其中即可。

 

      二.功能概述

      (一).代碼度量,統計各個方面的指標以確定代碼健壯性與重用性,測重代碼健康。

      (二).代碼分析,使用代碼規范檢查代碼,測重代碼風格與規范。

      (三).代碼編輯,包括編輯器,代碼大綱,代碼屬性,代碼比較,代碼搜索

      (四).依賴關系,分析代碼各模塊之間的依賴關系

      (五).支持多種語方,如C,C++,C#,JAVA等

      (六).報表輸出

      (七).統計報告

      更詳細的說明可參看:

      代碼閱讀分析工具Understand 2.0試用

 

      三.Understand代碼度量與Visual Studio代碼度量

      代碼度量是一組軟件度量值,使開發人員可以更好地了解他們正在開發的代碼。利用代碼度量,開發人員可以了解哪些類型和/或方法應該返工或進行更徹底的測試。開發團隊可以識別潛在的風險、了解項目的當前狀態,並跟蹤軟件開發的進度。

      Visual Studio 2008及其以后的Perfessional及其以上的版本提供了代碼度量功能。

      VS提供了代碼度量最核心的四個指標:Cyclomatic Complexity(圈復雜度),Depth of Inheritance(繼承深度),Class Coupling(類耦合度),Lines of Code(代碼行數);另外還有一個綜合這四個指標得出的一個評估值:Maintainability Index(可維護性指數)。

      Understand代碼度量則提供了更加詳細的分析指標與報告。

      如無特殊需求,Visual Studio自帶的代碼度量即可滿足日常使用。

 

      四.重要的度量參數簡介

      可維護性指數:計算一個介於 0 和 100 之間的指數值,表示維護代碼的相對容易度。值越大表示可維護性越好。該計算基於 Halstead Volume、圈復雜度和代碼的行數。按顏色標記的等級可用於迅速發現代碼中的故障點。綠色等級介於 20 和 100 之間,表示代碼的可維護性良好。黃色等級介於 10 和 19 之間,表示代碼的可維護性中等。紅色等級是介於 0 和 9 之間的等級,表示可維護性低。

      圈復雜度:衡量代碼在結構上的復雜程度。它通過計算程序流中的不同代碼路徑的數目(例如 if 塊、switch case 以及 do、while、foreach 和 for 循環),然后在總數中加 1 來創建。具有復雜控制流的程序需要更多單元測試才能實現良好的代碼覆蓋率,並且不容易維護。如果數值在1到4之間,說明代碼簡明,風險低;如果在5到10,說明代碼穩定,結構化良好,風險低;11到20,說明代碼有點復雜,風險中等;21到50,說明代碼非常復雜,風險高;大於50,說明代碼已失控,風險極高。一個正面典型的程序模塊的圈復雜度為10,20以內的圈復雜度都是可以接受的。

      可以參考以下兩篇文章

      淺談軟件度量

      Project Metrics in Project Analyzer的Complexity metrics章節

      繼承深度:指明擴展到類層次結構根的類定義的數目。層次結構越深,則越難了解特定方法和字段是在何處定義或/和重新定義的。在類級別,該數目是通過計算繼承樹中從 0 開始的類型之上的類型數目(不包括接口)來創建的。在命名空間和項目級別,該計算包括命名空間或項目內所有類型的最高繼承深度計算。好的繼承層次應在3以內,最好不要超過5層。

      類耦合:通過參數、局部變量、返回類型、方法調用、泛型或模板實例化、基類、接口實現、在外部類型上定義的字段以及屬性修飾來衡量與唯一類的耦合程度。該計算不包 括基元類型和內置類型,例如 int32、字符串和對象。良好的軟件設計要求類型和方法應具有較高的內聚力和較低的耦合。耦合較高表示設計難以重用和維護,這是因為它與其他類型之間存 在許多依存關系。目前還未查到權威文檔對此值取值范圍的說明,現行目標是盡可能的少。跟據經驗,推薦為20以內。

      代碼的行數:指明代碼中的大概行數。該計數基於 IL 代碼,因此並不是源代碼文件中的確切行數。該計算不包括空白、注釋、括號以及成員、類型和命名空間的聲明。計數過高可能表示某個類型或方法正在嘗試執行過多的工作,應予以拆分。還可能表示該類型或方法難以維護。目前無推薦值。

 

      五.Understand代碼度量參數

      官方文檔

Type

Name

Description

中文說明

Count

AltAvgLineBlank

Average number of blank lines for all nested functions or methods, including inactive regions.

 

Count

AltAvgLineCode

Average number of lines containing source code for all nested functions or methods, including inactive regions.

 

Count

AltAvgLineComment

Average number of lines containing comment for all nested functions or methods, including inactive regions.

 

Count

AltCountLineBlank

Number of blank lines, including inactive regions.

 

Count

AltCountLineCode

Number of lines containing source code, including inactive regions.

 

Count

AltCountLineComment

Number of lines containing comment, including inactive regions.

 

Complex

AvgCyclomatic

Average cyclomatic complexity for all nested functions or methods.

平均圈復雜度(標准計算方式)

Complex

AvgCyclomaticModified

Average modified cyclomatic complexity for all nested functions or methods.

平均圈復雜度(第二種計算方式)

Complex

AvgCyclomaticStrict

Average strict cyclomatic complexity for all nested functions or methods.

平均圈復雜度(第三種計算方式)

Complex

AvgEssential

Average Essential complexity for all nested functions or methods.

平均基本復雜度(標准計算方式)

Complex

AvgEssentialStrictModified

Average strict modified essential complexity for all nested functions or methods.

 

Count

AvgLine

Average number of lines for all nested functions or methods.

平均行數

Count

AvgLineBlank

Average number of blank for all nested functions or methods.

平均空白行數

Count

AvgLineCode

Average number of lines containing source code for all nested functions or methods.

平均包含代碼的行數

Count

AvgLineComment

Average number of lines containing comment for all nested functions or methods.

平均包含注釋的行數

Object Oriented

CountClassBase

Number of immediate base classes.

直接基類數,可能的話包括Object類

Object Oriented

CountClassCoupled

Number of other classes coupled to.

對像耦合度,包括.net框架對象

Object Oriented

CountClassDerived

Number of immediate subclasses.

直接子類數

Object Oriented

CountDeclClass

Number of classes.

類的個數

Object Oriented

CountDeclClassMethod

Number of class methods.

靜態方法個數,包括靜態構造方法

Object Oriented

CountDeclClassVariable

Number of class variables.

靜態字段個數

Count

CountDeclFile

Number of files.

文件的個數

Count/ Object Oriented

CountDeclFunction

Number of functions.

函數的個數,不包括接口方法,包括屬性方法,構造函數和一般方法

Object Oriented

CountDeclInstanceMethod

Number of instance methods.

實例方法個數

Object Oriented

CountDeclInstanceVariable

Number of instance variables.

實例字段個數

Object Oriented

CountDeclInstanceVariablePrivate

Number of private instance variables.

 

Object Oriented

CountDeclInstanceVariableProtected

Number of protected instance variables.

 

Object Oriented

CountDeclInstanceVariablePublic

Number of public instance variables.

 

Object Oriented

CountDeclMethod

Number of local methods.

本類方法個數

Object Oriented

CountDeclMethodAll

Number of methods, including inherited ones.

本類與繼承的方法個數

Object Oriented

CountDeclMethodConst

Number of local const methods.

 

Object Oriented

CountDeclMethodDefault

Number of local default methods.

 

Count/ Object Oriented

CountDeclMethodFriend

Number of local friend methods.

 

Object Oriented

CountDeclMethodPrivate

Number of local private methods.

本類私有方法個數

Object Oriented

CountDeclMethodProtected

Number of local protected methods.

本類保護方法個數

Object Oriented

CountDeclMethodPublic

Number of local public methods.

本類公共方法個數

Object Oriented

CountDeclMethodStrictPrivate

Number of local strict private methods.

 

Object Oriented

CountDeclMethodStrictPublished

Number of local strict published methods.

 

Object Oriented

CountDeclModule

Number of modules.

 

Object Oriented

CountDeclProgUnit

Number of non-nested modules, block data units, and subprograms.

 

Object Oriented

CountDeclSubprogram

Number of subprograms.

 

Count

CountInput

Number of calling subprograms plus global variables read.

被調用的次數。被同一方法多次調用只算一次,被字段調用則不計入此數。

Count

CountLine

Number of all lines.

代碼行數

Count

CountLineBlank

Number of blank lines.

代碼空白行數

Count

CountLineBlank_Html

Number of blank html lines.

 

Count

CountLineBlank_Javascript

Number of blank javascript lines.

 

Count

CountLineBlank_Php

Number of blank php lines.

 

Count

CountLineCode

Number of lines containing source code.

包含代碼的行數

Count

CountLineCodeDecl

Number of lines containing declarative source code.

聲名類代碼行數,方法聲名行也記入此數

Count

CountLineCodeExe

Number of lines containing executable source code.

純執行類代碼行數

Count

CountLineCode_Javascript

Number of javascript lines containing source code.

 

Count

CountLineCode_Php

Number of php lines containing source code.

 

Count

CountLineComment

Number of lines containing comment.

注釋類代碼行數

Count

CountLineComment_Html

Number of html lines containing comment.

 

Count

CountLineComment_Javascript

Number of javascript lines containing comment.

 

Count

CountLineComment_Php

Number of php lines containing comment.

 

Count

CountLineInactive

Number of inactive lines.

 

Count

CountLinePreprocessor

Number of preprocessor lines.

 

Count

CountLine_Html

Number of all html lines.

 

Count

CountLine_Javascript

Number of all javascript lines.

 

Count

CountLine_Php

Number of all php lines.

 

Object Oriented

CountOutput

Number of called subprograms plus global variables set.

調用其它方法的次數,多次調用同一方法只算一次調用。Return語句算一次調用。

Object Oriented

CountPackageCoupled

Number of other packages coupled to.

 

Complex

CountPath

Number of possible paths, not counting abnormal exits or gotos.

可以執行的代碼路徑,與圈復雜度相關

Count

CountSemicolon

Number of semicolons.

分號的數量

Count

CountStmt

Number of statements.

語句的數量,即使把多句話寫在一行內,仍然算多次

Count

CountStmtDecl

Number of declarative statements.

定義類語句的數量,包話方法聲名行

Count

CountStmtDecl_Javascript

Number of javascript declarative statements.

 

Count

CountStmtDecl_Php

Number of php declarative statements.

 

Count

CountStmtEmpty

Number of empty statements.

 

Count

CountStmtExe

Number of executable statements.

執行類語句的數量

Count

CountStmtExe_Javascript

Number of javascript executable statements.

 

Count

CountStmtExe_Php

Number of php executable statements.

 

Complex

Cyclomatic

Cyclomatic complexity.

圈復雜度(標准計算方式)

Complex

CyclomaticModified

Modified cyclomatic complexity.

圈復雜度(第二種計算方式)

Complex

CyclomaticStrict

Strict cyclomatic complexity.

圈復雜度(第三種計算方式)

Complex

Essential

Essential complexity.

基本復雜度(標准計算方式)

Complex

EssentialStrictModified

Strict Modified Essential complexity.

 

Complex

Knots

Measure of overlapping jumps.

 

Complex

MaxCyclomatic

Maximum cyclomatic complexity of all nested functions or methods.

最大圈復雜度(標准計算方式)

Complex

MaxCyclomaticModified

Maximum modified cyclomatic complexity of nested functions or methods.

最大圈復雜度(第二種計算方式)

Complex

MaxCyclomaticStrict

Maximum strict cyclomatic complexity of nested functions or methods.

最大圈復雜度(第三種計算方式)

Complex

MaxEssential

Maximum essential complexity of all nested functions or methods.

 

Complex

MaxEssentialKnots

Maximum Knots after structured programming constructs have been removed.

 

Complex

MaxEssentialStrictModified

Maximum strict modified essential complexity of all nested functions or methods.

 

Complex/ Object Oriented

MaxInheritanceTree

Maximum depth of class in inheritance tree.

本類繼承層次

Complex

MaxNesting

Maximum nesting level of control constructs.

最大嵌套層次,與圈復雜度相關

Complex

MinEssentialKnots

Minimum Knots after structured programming constructs have been removed.

 

Object Oriented

PercentLackOfCohesion

100% minus the average cohesion for package entities.

方法內聚缺乏度百分比。其要求類中每一個方法都要使用類中的全部字段。如果使用了3.5以上的自動屬性,其自動生成的匿名字段將不會被任何一個方法使用,會導致此度量值不會為最優的結果:0

Complex/ Count

RatioCommentToCode

Ratio of comment lines to code lines.

代碼注釋率

Complex

SumCyclomatic

Sum of cyclomatic complexity of all nested functions or methods.

圈復雜度之和(標准計算方式)

Complex

SumCyclomaticModified

Sum of modified cyclomatic complexity of all nested functions or methods.

圈復雜度之和(第二種計算方式)

Complex

SumCyclomaticStrict

Sum of strict cyclomatic complexity of all nested functions or methods.

圈復雜度之和(第三種計算方式)

Complex

SumEssential

Sum of essential complexity of all nested functions or methods.

基本復雜度之和(標准計算方式)

Complex

SumEssentialStrictModified

Sum of strict modified essential complexity of all nested functions or methods.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM