Subject: SPM
Subject: SPM
Lecture 9
Software Metrics
Software Size Metrics: Summary
Requirement
Length Design
LOC
Code
Halstead’s
Function point
Software Feature point
Functionality
size Use-case point
Object point
10
Length: Halstead’s Work /1
Maurice Halstead’s Theory (1971~1979):
A program P is a collection of tokens, composed
of two basic elements: operands and operators
Operands are variables, constants.
Operators are defined operations in a
programming language
if … else a, b, x
(language constructs) + -> = ; 100
main()
goto
11
Length: Halstead’s Work /2
Number of distinct operators in the program (n1)
Number of distinct operands in the program (n2)
Total number of occurrences of operators in the
program (N1)
Total number of occurrences of operands in the
program (N2)
B= E
2/3
3000
Conclusion: the bigger program needs more
time to be developed and more bugs
remained
Example 1
For the following C program:
#include<stdio.h>
main()
{
int a ; Operands
scanf (“%d”, &a);
if ( a >= 10 )
if ( a < 20 ) printf ("10 < a< 20 %d\n" , a);
else printf ("a >= 20 %d\n" , a);
else printf ("a <= 10 %d\n" , a);
}
Example 1 (cont’d)
Operators Number of Operators Number of
occurrences occurrences
# 1 <= 1
include 1 \n 3
stdio.h 1 printf 3
<…> 1 < 3
main 1 >= 2
(…) 7 if … else 2
{…} 1 & 1
int 1 , 4
; 5 %d 4
scanf 1 “…“ 4
μ1 = 20 N1 = 47
Example 1 (cont’d)
Operands Number of occurrences
a 10
10 3
20 3
n2 = 3 N2 = 16
n1 = 20 N1 = 47
Program length: N = N1 + N2 = 63
Program Estimated length:
N^ =n 1
log 2 n1 +n 2 log2 n 2 = 20 log 2 20 + 3log 2 3=91.1934
Example 1 (cont’d)
E=V*D= 20*16 * 63log223
2*3
E=V*D= 15177.7
Remaining Bugs
B=0.19
Example 2
Length: Halstead’s Work /7
Critics of Halstead’s work
Developed in the context of assembly languages and
too fine grained for modern programming
languages.
The notions of time to develop and remaining bugs
are arguable.
Unable to be extended to include the size for
specification and design.
Length: Code - Problems
One of the problems with text-based definition of
length is that the line of code measurement is
increasingly less meaningful as software
development turns to more automated tools, such
as:
Tools that generate code from specifications
Visual programming tools