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

Scores can be adjusted with three different options:

nesting-penalty

See section —nesting-penalty.

demi-nesting-penalty

See section —demi-nesting-penalty.

scale

See section —scale.

The raw score is the number of lines or statements, whichever is greater, adjusted by a factor for the depth of the logic. Statements are nested when they are inside of a block of statements for a “block” statement (viz., “do”, “for”, “if”, “switch” or “while”). Statements within blocks used to constrain the scope of variables (not controlled by a block statement) are not multiplied by this factor.

Expressions are nested when contained within parentheses. The cost of these is different. Block level nesting multiplies the score for the block by the `--nesting-penalty` factor (2.0 by default). Nested expressions are multiplied by the `--demi-nesting-penalty`, the square root of `--nesting-penalty` by default.

Some attempt is made to judge the complexity of an expression. A complicated expression is one that contains an assignment operator, more than one relation operator, or a mixture of “and” and “or” operators with any other different kind of non-arithmetic operator. Expression scores are minimized by:

• Doing assignments outside of boolean expressions, or at least parenthesizing them.
• Parenthesizing each relationship operation in an expression of multiple “and” and/or “or” operations. Yes, precedence parses them correctly, but it is less clear.
• Parenthesizing groups of “and” and “or” operations so that operators of only one type appear at one level. For example, the first expression below instead of the second. Yes, precedence means the effect is the same, but we’re after code clarity so that correctness is more obvious.  ```1: ((a && b) || (c && d)) 2: (a && b || c && d) ```

The first adds 2 to the raw score (before dividing by the scaling factor). The latter will add 5, assuming a `demi-nesting-penalty` of `1.41`.

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

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