[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
‘pmccabe’ does not score logic conditions very well.
It overcharges for simple logical operations, it doesn’t charge for
comma operators, and it undercharges for mixing assignment operators
and relational operators and the and
and or
logical
operators.
For example:
xx = (A && B) || (C && D) || (E && F); |
scores as 6
. Strictly speaking, there are, indeed, six code
paths there. That is a fairly straight forward expression that is not
nearly as complicated as this:
if (A) { if (B) { if (C) { if (D) a-b-c-and-d; } else if (E) { a-b-no_c-and-e; } } } |
and yet this scores exactly the same. This program reduces the cost
to very little for a sequence of conditions at the same level. (That
is, all and
operators or all or
operators.) so the raw score
for these examples are 4 and 35, respectively (1 and 2 after scaling,
see section --scale
).
If you nest boolean expressions, there is a little cost, assuming you
parenthesize grouped expressions so that and
and or
operators do not appear at the same parenthesized level. Also
assuming that you do not mix assignment and relational and boolean
operators all together. If you do not parenthesize these into
subexpressions, their small scores get multiplied in ways that
sometimes wind up as a much higher score.
The intent here is to encourage easy to understand boolean expressions. This is done by,
&&
operators at the bottom level and all ||
operators in the
nested level -\- or vice versa)
&&
or ||
expressions)
if
statements, if convenient.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated by Bruce Korb on May 15, 2011 using texi2html 1.82.