0% found this document useful (0 votes)
106 views13 pages

Lecture 4 SoftwareProductMetrics LOC Halstead

Uploaded by

rawaidh0001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views13 pages

Lecture 4 SoftwareProductMetrics LOC Halstead

Uploaded by

rawaidh0001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

LECTURE 04 : SOFTWARE METRICS:

PRODUCT METRICS: LOC &


HALSTEAD
COCS455 – SOFTWARE RELIABILITY, ROBUSTNESS
AND SECURITY

DR . NORAZAH YUSOF
FACULTY OF COMPUTING AND INFORMATION TECHNOLOGY RABIGH,
KING ABDULAZIZ UNIVERSITY ( WOMEN SEC T ION)

INTRODUCTION TO SOFTWARE
METRICS
• Measuring software reliability is challenging because we don't have a good understanding of the
nature of software.
• It is difficult to find a suitable method to measure software reliability and most of the aspects
connected to software reliability.
• If we cannot measure the reliability directly, something (internal) can be measured that reflects the
features related to reliability.
• Software metrics is a standard of measure that contains many activities which involve some degree of
measurement.
• Sommerville (2016) classified software metrics into two categories:
1. Product metrics describe the characteristics of the product such as size, complexity, design
features, performance, reliability and quality level. These metrics help predict characteristics of
the software.
2. Process metrics can be used to improve software development and maintenance and support
process management. Examples include the effectiveness of defect removal during
development, the pattern of testing defect arrival, and the response time of the fix process.
PRODUCT METRICS
• Product metrics are the measures of various characteristics of the software product.
• These metrics help in the assessment if the product is right sufficient through records on attributes such as
usability, reliability, maintainability, etc.
• These measurements are taken from the actual body of the source code.
• The most two important software characteristics are:
• Size and complexity of software.
• Quality and reliability of software.
• Examples:
i. Software size is thought to be reflective of complexity, development effort, and reliability. Lines of
Code (LOC), or thousands LOC (KLOC), is an initial intuitive approach to measuring software size.
ii. Function point metric is a technique to measure the functionality of proposed software development
based on the count of inputs, outputs, inquires, and interfaces.
iii. Test coverage metric are a way of estimating fault and reliability by performing tests on software
products, based on the assumption that software reliability is a function of the portion of software that has
been successfully verified or tested.
iv. Complexity-oriented metrics is a way of determining the complexity of a program's control structure
by simplifying the code into a graphical representation. Complexity is directly related to software
reliability, so representing complexity is important.

PROCESS METRICS
• Process metrics are the measures of various characteristics of the software development process. They are
used to measure the characteristics of methods, techniques, and tools used for developing software.
• Process metrics describe the effectiveness and quality of the processes that produce the software product.
• The goal of process metric is to do the right job on the first time through the process, The quality of the
product is a direct function of the process.
• So process metrics can be used to estimate, monitor, and improve the reliability and quality of software.
• Examples are:
• The effort required in the process
• Time to produce the product
• Effectiveness of defect removal during development
• Number of defects found during testing
SOFTWARE SIZE MERTICS

• Software size is one of the attributes of a software product. It can be measured statically, i.e. without
executing the system.
• Size measurement must reflect Length, Functionality and Complexity.
• Tow common approaches for software size metrics are:
I. LOC (Lines of Codes) or KLOC (thousands Line of Code)
● This metric represents metrics based on the physical completed size of software, such ae the
number of lines of code or the number of software statements.
II. FPs (Function points)
● This metric represents the result of applying a measure from the group of functional size
measurement (FSM) methods. These estimating methods are based on the functionality
specified by the software project requirements.

LENGTH of Code

• In a software development effort, there are three major development products:


I. Specification
II. Design
III. Code
• The length of the specification can indicate how long the design is likely to be, which in turn is
a predictor of code length.
• Traditionally, code length refers to text-based code length.
Lines of Code (LOC)

• The most commonly used measure of source code program length is the number of lines of code
(LOC).
● NCLOC : non-comment line of code.
● CLOC : comment line of code.
• By measuring NCLOC and CLOC separately we can define: Total length (LOC) = NCLOC +
CLOC

LOC : VARIATION

I. Count of physical lines including blank lines.


II. Count of all lines except blank lines and comments.
III. Count of all statements except comments (statements taking more than one line count as only one
line).
IV. Count of all lines except blank lines, comments, declarations and headings.
V. Count of only executable statements, not including exception conditions.
LOC :
EXAMPLE
Consider this snippet of C code as an example of the ambiguity encountered when determining source
lines of code (SLOC):

1 for (i = 0; i < 100; i++) printf("hello"); /* How many lines of code is


. this? */

2
.

LOC :
EXAMPLE
Consider this snippet of C code as an example of the ambiguity encountered when determining source
lines of code (SLOC):

1 for (i = 0; i < 100; i++) printf("hello"); /* How many lines of code is


. this? */

In this example, there are:


• 1 physical line of code (LOC),
• 2 logical lines of code (LLOC) (for statement and printf statement),
• 1 comment line.
LOC :
EXAMPLE
Consider this snippet of C code as an example of the ambiguity encountered when determining source
lines of code (SLOC):
2.

In this example, there are:


• 4 physical lines of code (LOC): is placing braces work to be estimated?
• 2 logical lines of code (LLOC): what about all the work writing non-statement lines?
• 1 comment line: tools must account for all code and comments regardless of comment placement.

LOC : ADVANTAGES AND DISADVANTAGES

• Advantages of LOC:
I. Automation of the counting process can be done.
II. Intuitive as the measurements are easily understood
III. Correlates with programming effort (& cost)

• Disadvantages of LOC:
IV. Vague definition and lack of counting standards.
V. Lines of code is language dependent
VI. Not available for early planning, but only available at coding phase.
VII. Lines of code depends on the skill set of the developer
INTRODUCTION TO HALSTEAD’S
METRICS
• According to Halstead: “ A computer program is an implementation of an algorithm considered to be a
collection of tokens that can be classified as either operators or operands”
• Halstead’s metrics are included in a number of current commercial tools that count software lines of
code.
• This is done by counting the tokens and determining which are operators and which are operands.
• It also allows to evaluate testing time, vocabulary, size, difficulty, errors and efforts for source code.

HALSTEAD METRIC BASED


MEASURES
• The following base measures can be collected :
• n1 = Number of unique operators.
• n2 = Number of unique operands.
• N1 = Total number of occurrences of operators.
• N2 = Total number of occurrences of operands.
HALSTEAD METRICS :
• TheDESCRIPTIONS
following are the Halstead metrics:
1. Halstead Program Length is the total number of operator occurrences and the total number of
operand occurrences.
N = N1 + N2
and estimated program length is N = n1 log2 n1 + n2 log2 n2

2. Halstead Vocabulary – is the total number of unique operator and unique operand occurrences.
It is calculated by:
n = n1 + n2

3. Program Volume – represents the size, in bits, of space necessary for storing the program.
• The properties V, N, and the number of lines in the code are shown to be linearly connected and
equally valid for measuring relative program size.
V = Size * (log2 vocabulary) = N * log2(n)

HALSTEAD METRICS : DESCRIPTIONS


1. Program Difficulty – This parameter shows how difficult to handle the program is. D = (n1 / 2)
* (N2 / n2)
• As the volume of the implementation of a program increases, the difficulty increases.
2. Programming Effort – Measures the amount of mental activity needed to translate the existing
algorithm
into implementation in the specified program language.
E=D*V
3. Programming Time – Shows time (in minutes) needed to translate the existing algorithm into
implementation in the specified program language.
T = E / S = E /18 seconds
• S: the time required by the human brain requires to carry out the most elementary decision.
• Halstead uses 18.
HALSTEAD METRICS : COUNTING RULES
1. Comments are not considered.
2. The identifier and function declarations are not considered
3. All the variables and constants are considered operands.
4. Global variables used in different modules of the same program are counted as multiple occurrences
of the same variable.
5. Local variables with the same name in different functions are counted as unique operands.
6. Functions calls are considered as operators.
7. All looping statements e.g., do {…} while ( ), while ( ) {…}, for ( ) {…}, all control statements e.g., if
()
{…}, if ( ) {…} else {…}, etc. are considered as operators.
8. In control construct switch ( ) {case:…}, switch as well as all the case statements are considered as
operators.
9. The reserve words such as return, default, continue, break, etc., are considered as operators.
10. All the brackets, commas, and terminators are considered as operators.

COUNTING RULES FOR C


LANGUAGE
1. GOTO is counted as an operator and the label is counted as an operand.
2. The unary and binary occurrence of “+” and “-” are dealt separately. Similarly “*” (multiplication
operator) are dealt separately.
3. In the array variables such as “array-name [index]” “array-name” and “index” are considered as
operands and [ ] is considered as operator.
4. In the structure variables such as “struct-name, member-name” or “struct-name -> member-name”,
struct-name, member-name are taken as operands and ‘.’, ‘->’ are taken as operators. Some names of
member elements in different structure variables are counted as unique operands.
5. All the hash directive are ignored.
EXERCISE
1
Given the C coding,
i. List out the operators and operands
ii. Calculate the values of software science measures:
a. Program length
main()
b. Estimated length
{
c. Vocabulary int a, b, c, avg;
d. Program volume scanf("%d %d %d", &a, &b, &c); avg =
e. Difficulty (a + b + c) / 3;
f. Effort printf("avg = %d", avg);
g. Time }

operators occurrences operands occurrences


EXERCISE 1: Solueon
main a
Given the C coding, () b
i. list out the operators and operands {} c
int avg
main()
{ scanf “%d %d
int a, b, c, avg; %d”
scanf("%d %d %d", &a, &b, &c); & 3
avg = (a + b + c) / 3;
= “avg = %d”
printf("avg = %d", avg);
} +
/
prin_
,
;
n1= ?? N1= ?? n2= ?? N2=??
operators occurrences operands occurrences
EXERCISE 1: Solueon
main 1 a 3
Given the C coding, () 4 b 3
i. list out the operators and operands {} 1 c 3
main() :int 1 avg 3
{ scanf 1 “%d %d 1
int a, b, c, avg; %d”
scanf("%d %d %d", &a, &b, &c); & 3 3 1
avg = (a + b + c) / 3;
printf("avg = %d", avg); = 1 “avg = %d” 1
} + 2
/ 1
prin_ 1
, 7
; 4
n1=12 N1= 27 n2=7 N2=15

EXERCISE 1: Solueon

a. Program Length = N = N1 + N2 = 27 + 15 = 42

b. Es9mated length= N= n1log2n1 + n2log2n2


= 12 x log212 + 7 x log27 = 62.67
c. Vocabulary = n = n1 + n2 = 12 + 7 =
19
d. Volume = V = N x log2n = 42 x log219 = 178.4

e. Difficulty = D = n1/2 x N2/n2 = 12/2 x 15/7 = 12.85

f. Effort = E = D x V = 12.85 x 178.4 = 2292.44


g. Time = E / 18 seconds = 2292.44 / 18 = 127.357
HALSTEAD’S METRICS : ADVANTAGES AND DISADVANTAGES

• Advantages:
I. simple to calculate.
II. measures overall quality of the programs.
III. predicts the rate of error.
IV. predicts maintenance effort.
V. useful in scheduling and reporting projects.
VI. can be used for any programming language.

• Disadvantages:
VII. depends on the complete code
VIII. has no use as a predictive estimating model

EXERCISE
2
Given the C coding,
i. list out the operators and operands
ii. calculate the values of software science measures:
a. Program main()
length {
b. Estimated int a; scanf("%d", &a); if ( a >= 10 )
length if ( a < 20 ) printf(“10 < a < 20 %d\n”, a);
c. Vocabulary else printf(“ a >= 20 %d\n”, a); else printf(“ a <=
10 %d\n”, a);
d. Program
}
volume
e. Difficulty
f. Effort
g. Time
SELF-TEST -- LECTURE 04
1. Define software metric. Discuss its categories.
2. List TOW examples of product metrics and process metrics.
3. List ONE advantage and ONE disadvantage of LOC and HALSTEAD metrics.
4. + All EXERCISEs

You might also like