From da1921b4d005b2cdcf26ad49ada050123fd54b22 Mon Sep 17 00:00:00 2001 From: Roman Ivanov Date: Thu, 18 Jun 2015 00:00:56 -0700 Subject: [PATCH] NPathComplexity: extend documentation to make clear how it works. #1218 --- src/xdocs/config_metrics.xml | 63 +++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/src/xdocs/config_metrics.xml b/src/xdocs/config_metrics.xml index 0eea6b4e1..53f73a673 100644 --- a/src/xdocs/config_metrics.xml +++ b/src/xdocs/config_metrics.xml @@ -416,13 +416,68 @@ class CC { paths through a function. It takes into account the nesting of conditional statements and multi-part boolean expressions (e.g., A && B, C || D, etc.). +
+ The NPATH metric was designed base on Cyclomatic complexity to + avoid problem of Cyclomatic complexity metric like nesting level within a function. +

+

+ Metic wsa described at "NPATH: a measure of execution path complexity and its applications". If you need detaled description of algorithm, please read that article, + it well written and have number of examples and details.

+

Here is some quotes:

+ +
An NPATH threshold value of 200 has been established + for a function. The value 200 is based on studies done + at AT&T Bell Laboratories [1988 year]. +
+ +
+ Some of the most effective methods of reducing the NPATH value include
+ - distributing functionality,
+ - implementing multiple if statements as a switch statement
+ - creating a separate function for logical expressions with a high count of and (&&) and or (||) operators. +
+ +
+ Although strategies to reduce the NPATH complexity + of functions are important, care must be taken not to + distort the logical clarity of the software by applying a + strategy to reduce the complexity of functions. That is, + there is a point of diminishing return beyond which a + further attempt at reduction of complexity distorts the + logical clarity of the system structure. +
+ + + + + + + + + + + + + + + + + + +
Structure Complexity expression
ifNP((if-range))+NP((expr))+1
if-elseNP((if-range))+NP((else-range))+NP((expr))
whileNP((while-range))+NP((expr))+1
do whileNP((do-range))+NP((expr))+1
forNP((for-range))+NP((exprl))+NP((expr2))+NP((expr3))+1
switchNP((expr))+ S(i=1:i=n)NP((case-range(i)))+ NP((default-range))
?NP((exprl))+NP((expr2))+NP((expr3))+2
goto label1
break1
ExpressionsNumber of && and || operators in expression
continue1
return1
sequential1
Function call1
C functionP(i=1:i=N) NP(Statement(i))
+ +

- Rationale: Nejmeh says that his group had an informal NPATH + Rationale: Nejmeh says that his group had an informal NPATH limit of 200 on individual routines; functions that exceeded this value were candidates for further decomposition - or at - least a closer look. + least a closer look. + Please do not be fanatic with limit 200 + - choose number that suites your project style. Limit 200 is + empirical number base on some sources of at AT&T Bell Laboratories + of 1988 year.

@@ -452,11 +507,11 @@ class CC {

- To configure the check with a threshold of 20: + To configure the check with a threshold of 1000:

<module name="NPathComplexity"> - <property name="max" value="20"/> + <property name="max" value="1000"/> </module>