[ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

## 2.2 Complexity Measurement Algorithm

Fundamentally, this program counts non-comment source lines and examines elements of parenthesized expressions. This score is multiplied by a nesting scoring factor for each layer of code nesting.

A parenthesized expression is scanned for operators. If they are all arithmetic operators, or all arithmetic and one relational operator, the score is zero. If all the operators are boolean ands or they are all ors, then the score is one. An assignment operator with arithmetic operators also scores one. If you mix relational operators and all ands or all ors, the score is the number of boolean elements. If you mix ands and ors at the same parenthetical level, the two counts are multiplied, unless the boolean element count is higher.

Fundamentally, do not use multiple relational or boolean operators at the same parenthetical level, unless they are all boolean ands or they are all boolean ors. If you use boolean operators and relational operators in one expression, you are charged one statement for each boolean element.

After scoring each statement and any parenthesized expressions, the score is multiplied by any encompassing controlled block and added to the score of that block. A “controlled block” is a curly-braced collection of statements controlled by one of the statement controlling statements do, for, else, if, switch, or while. Stand alone blocks for scoping local variables do not trigger the multiplier.

You may trace the scores of parenthesized expressions and code blocks (see section trace output file). You will see the raw score of the code block or expression.

The final score is the outermost score divided by the “scaling factor”, See section complexity scaling factor.

 [ < ] [ > ] [ << ] [ Up ] [ >> ]

This document was generated by Bruce Korb on May 15, 2011 using texi2html 1.82.