|
| 1 | +--- |
| 2 | +title: "Software Complexity" |
| 3 | +layout: notes |
| 4 | +--- |
| 5 | + |
| 6 | +# Complexity Measures/Metrics |
| 7 | +* LOC - a function of complexity |
| 8 | +* Halstead Complexity Measures |
| 9 | +* McCabe’s Complexity Measures |
| 10 | +* McClure's Complexity Metric |
| 11 | + |
| 12 | +# Halstead’s Software Science (entropy measures) |
| 13 | +* Computer program in software science is considered a series of operator/operator tokens |
| 14 | + - n<sub>1<sub> - number of distinct operators |
| 15 | + - n<sub>2</sub> - number of distinct operands |
| 16 | + - N<sub>1</sub> - total number of operators |
| 17 | + - N<sub>2</sub> - total number of operands |
| 18 | +* All software Sicence measures built off of these |
| 19 | + |
| 20 | +# Example Halstead Complexity Measures |
| 21 | + if (k < 2) { |
| 22 | + if (k > 3) |
| 23 | + x = x * k; |
| 24 | + } |
| 25 | + |
| 26 | +* Distinct operators: if ( ) { } > < = * ; |
| 27 | +* Distinct operands: k 2 3 x |
| 28 | + |
| 29 | +* n<sub>1</sub> = 10 <br/> |
| 30 | + n<sub>2</sub> = 4<br/> |
| 31 | + N<sub>1</sub> = 13<br/> |
| 32 | + N<sub>2</sub> = 7 |
| 33 | + |
| 34 | +* Different sources compute differently |
| 35 | + |
| 36 | +# Halstead Metrics |
| 37 | + |
| 38 | + |
| 39 | +* Length (Size): N = N<sub>1</sub> + N<sub>2</sub> |
| 40 | +* Vocabulary: n = n<sub>1</sub> + n<sub>2</sub> |
| 41 | +* Estimated length: N̂ = n<sub>1</sub> log<sub>2</sub> n<sub>1</sub> + n<sub>2</sub> log<sub>2</sub> n<sub>2</sub> |
| 42 | + |
| 43 | + - Close estimate of length for well structured programs |
| 44 | + |
| 45 | +* Purity ratio: PR = N̂ / N |
| 46 | + |
| 47 | +# Program Complexity |
| 48 | + |
| 49 | +* Volume: V = N log<sub>2</sub> n |
| 50 | + |
| 51 | + - Number of bits to provide a unique designator for each of the n items in the program vocabulary. |
| 52 | + |
| 53 | +* Program effort: E = V / L |
| 54 | + |
| 55 | + - where, L = V<sup>*</sup> / V, and |
| 56 | + - V<sup>*</sup> is the volume of most compact design implementation |
| 57 | + - This is a good measure of program understandability |
| 58 | + - L can be estimated with: (2 / n<sub>1</sub>) (n<sub>2</sub> / N<sub>2</sub>) |
| 59 | + |
| 60 | +# McCabe’s Complexity Measures |
| 61 | +* McCabe’s metrics are based on a control flow representation of the program. |
| 62 | +* A program graph is used to depict control flow. |
| 63 | +* Nodes represent processing tasks (one or more code statements) |
| 64 | +* Edges represent control flow between nodes |
| 65 | + |
| 66 | +# Cyclomatic Complexity |
| 67 | +* Set of independent paths through the graph (basis set) |
| 68 | + |
| 69 | +* V(G) = E – N + 2 |
| 70 | + - E is the number of flow graph edges |
| 71 | + - N is the number of nodes |
| 72 | + |
| 73 | +* V(G) = P + 1 |
| 74 | + - P is the number of predicate nodes |
| 75 | + |
| 76 | +# Cyclomatic Complexity Meaning |
| 77 | +* V(G) is the number of (enclosed) regions/areas of the planar graph |
| 78 | +* Number of regions increases with the number of decision paths and loops. |
| 79 | +* A quantitative measure of testing difficulty and an indication of ultimate reliability |
| 80 | +* Experimental data shows value of V(G) should be no more then 10. Testing is very difficulty above this value. |
| 81 | + |
| 82 | +# McClure's Complexity Metric |
| 83 | + |
| 84 | +* Complexity = C + V |
| 85 | + |
| 86 | + - C is the number of comparisons in a module |
| 87 | + - V is the number of control variables referenced in the module |
| 88 | +* Similar to McCabe’s but with regard to control variables. |
0 commit comments