14
Software Metrics

Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity

Embed Size (px)

Citation preview

Page 1: Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity

Software Metrics

Page 2: Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity

Software Metrics

•White Box Metrics–LOC–Halstead’s Software Science–McCabe’s Cyclomatic Complexity

Page 3: 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

Page 4: Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity

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.

Page 5: Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity

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.

Page 6: Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity

LOC• examples of use include:

–productivity KLOC/person-month –quality faults/KLOC –cost $$/KLOC –Documentation doc_pages/KLOC

Page 7: Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity

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.

Page 8: Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity

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.

Page 9: Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity

• 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 :

Page 10: Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity

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;

Page 11: Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity

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; } } }

Page 12: Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity

Halstead’s bug prediction

Page 13: Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity
Page 14: Software Metrics. White Box Metrics – LOC – Halstead’s Software Science – McCabe’s Cyclomatic Complexity

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.