* Cyclomatic complexity - example of a complexity metric
* V(G) = e - n + p
(edges minus nodes plus connected components)
* BUT! this can be shown to be the SAME as
the number of DECISIONS in the program plus one
* Halstead has a complexity metric
as well as those size metrics mentioned previously:
* recall Halstead's volume...
n1 - number of distinct operators
n2 - number of distinct operands
N1 - total occurrences/frequency of operators
N2 - total occurrences/frequency of operands
* Vocabulary n = n1 + n2
(sum of the numbers of distinct operators
and operands)
* Length N = N1 + N2
(sum of the total occurrences/frequency of
operators and operands -- a LENGTH metric, as we noted)
* Volume V = N log2 (n)
NOW a few more:
* N2 / n2 - total occs of operands / number of distinct operands
IF you buy that variables being changed more frequently --
N2 / n2 being larger as a result --
means that those variables would be harder to understand,
then you might also buy that:
ease of reading or writing could be defined as:
D = (n1 * N2)/(2 * n2)
(but doesn't this assume a certain imperative style
of programming?)
* live variables -
how many variables does a programmer need to keep track
of?
* a variable is considered LIVE from its first to its
last reference in a module; (better be less than or equal to
its scope...!)
* for a statement, the number of live variables could be
considered as a measure of degree of complexity of
the statement;
...you could, for a module, compute the average number of
live variables per statement;
* (note this is looking at complexity more in terms of data used,
rather than logic as in cyclomatic complexity)
* span - the number of statements between two *successive*
uses of a variable
* if a variable is used n times in a module,
there are (n-1) spans for that variable
* average span size is the average number of executable statements
between two successive references of a variable
* a larger span might imply the reader has to remember a variable's
meaning across more statements (for longer time?)
...another complexity measure;