Lecture 4 SoftwareProductMetrics LOC Halstead
Lecture 4 SoftwareProductMetrics LOC Halstead
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
• 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
2
.
LOC :
EXAMPLE
Consider this snippet of C code as an example of the ambiguity encountered when determining source
lines of code (SLOC):
• 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.
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)
EXERCISE 1: Solueon
a. Program Length = N = N1 + N2 = 27 + 15 = 42
• 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