Understand简明参考
Understand全称为Scientific Toolworks Understand,,是一款源代码阅读分析软件,使用它可以大大提高代码阅读效率。此软件亦有架构分析,代码评审与度量,生成软件质量统计与报表等功能。
官方网站:https://www.scitools.com/features/metrics.php
一.安装
傻瓜式安装,安装过程中使用算号器生成可用序列号填入其中即可。
二.功能概述
(一).代码度量,统计各个方面的指标以确定代码健壮性与重用性,测重代码健康。
(二).代码分析,使用代码规范检查代码,测重代码风格与规范。
(三).代码编辑,包括编辑器,代码大纲,代码属性,代码比较,代码搜索
(四).依赖关系,分析代码各模块之间的依赖关系
(五).支持多种语方,如C,C++,C#,JAVA等
(六).报表输出
(七).统计报告
更详细的说明可参看:
三.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. |
|