Upload
christiana-hawkins
View
218
Download
6
Embed Size (px)
Citation preview
Software Metrics
Software Metrics
•White Box Metrics–LOC–Halstead’s Software Science–McCabe’s Cyclomatic Complexity
White Box Metrics•White Box Metrics–Linguistic:
• LOC• Halstead’s Software Science
–Structural:• McCabe’s Cyclomatic Complexity• Information Flow Metric
–Hybrid:• Syntactic Interconnection
Types of White Box Metrics -Linguistic Metrics:
• measuring the properties of program/specification text without interpretation or ordering of the components.
-Structural Metrics: • based on structural relations between objects in program; usually based on properties of control/data flowgraphs [e.g.
number of nodes, links, nesting depth], fan-ins and fan-outs of
procedures, etc.
-Hybrid Metrics: • based on combination (or on a function) of linguistic and
structural properties of a program.
Linguistic Metrics Lines of code/statements (LOC)• perhaps the simplest:
– count the number of lines of code (LOC) and use as a measure
of program complexity. – Simple to use:
• if errors occur at 2% per line, a 5000 line program should have about 100 errors.
LOC• examples of use include:
–productivity KLOC/person-month –quality faults/KLOC –cost $$/KLOC –Documentation doc_pages/KLOC
LOC• Various studies indicate:
– error rates ranging from 0.04% to 7% when measured against statement counts; – LOC is as good as other metrics for small programs– LOC is optimistic for bigger programs. – LOC appears to be rather linear for small programs (<100
lines),– but increases non-linearity with program size.– Correlates well with maintenance costs – Usually better than simple guesses or nothing at all.
A basic overview:• based on two easily obtained program parameters:
– the number of distinct operators in program – the number of distinct operands in program
• paired operators such as: "begin...end", "repeat...until“
are usually treated as a single operator. • the program length is defined by:
• define the following: – N1 = total count of all operators in program. – N2 = total count of all operands in program.
• then the actual Halstead length is given as:
– [usually accepted as more appropriate] –which is basically a static count of the number of
tokens in program.
• the vocabulary of a program is defined as the sum
of the number distinct operands and operators :
Example of program length
48 7 log 7 + 9 log 9 = H
1.0) 1, x,z, pow, 0, (y, 7 = n
/)(minus), - *, =,!
while,(sign), =,- <,(if, 9 = n
22
2
1
if (y < 0) pow = - y;else pow = y;z = 1.0;while (pow != 0) { z = z * x; pow = pow - 1; }if (y < 0) z = 1.0 / z;
Example of program length
48 7 log 7 + 9 log 9 = H
temp)list, k, last, N, 1, (j, 7 = n
if) >,[], +, -, +,+ <,=, (for, 9 = n
22
2
1
for ( j=1; j<N; j++) { last = N - j + 1; for (k=1; k <last; k ++) { if (list[k] > list[k+1]) { temp = list[k]; list[k] = list[k+1]; list[k+1] = temp; } } }
Halstead’s bug prediction
Known weaknesses:Exercise : Program Effort
–call depth not taken into account• a program with a sequence 10 successive calls more
complex than one with 10 nested calls
–An if-then-else sequence given same weight as a loop
structure.–added complexity issues of nesting if-then-else or
loops not taken into account, etc.