Halstead’s Software Metrics
Halstead's hypothesis is a method for calculating software products' size, development effort, and development cost. To generate the formulas for overall programme length, possible minimal volume, actual volume, effort, and development time, Halstead's used a few primitive programme parameters.
According to Halstead’s statement, "A computer programme is an implementation of an algorithm that is believed to be a collection of tokens that can be classed as either operators or operands."
Also read V Model in Software Engineering
Count of Token
A computer programme is defined as a collection of tokens classed as operators or operands in these metrics. These basic symbols can be used to determine all software science measurements. Tokens are the symbols that are used to represent something.
The fundamental metrics are:
- n1 is the number of distinct operators.
- n2 is the number of separate operands.
- N1 is the total number of instances of each operator.
-
N2 is the total number of occurrences of operands.
The program's size can be stated as N = N1 + N2 in terms of unlimited tokens used.
In addition to the preceding, Halstead specifies:
- n1* denotes the number of possible operators.
- n2* is the number of possible operands.
The minimal feasible number of operators and operands for a module and a programme, according to Halstead, are n1* and n2*.
Halstead’s Software Metrics
-
The Volume of the programme (V)
The standard unit for size "bits" is the unit of measurement for volume. If a standard binary encoding for the vocabulary is
employed, it is the actual size of the programme.
V=N*log2n
-
Level of the Program (L)
L is a number that ranges from zero to one, with L=1 denoting a programme written at the most excellent level possible
(i.e., with minimum size).
L=V*/V
-
The Difficulty of the Program
The number of unique operators in the programme determines the program's complexity level or error-proneness (D).
(n1/2) * (N2/n2) = D
-
Effort Involved in Programming (E)
Fundamental mental discriminations are the unit of measurement for E.
E=V/L=D*V
-
Program Length Approximated
The first hypothesis of software science, according to Halstead, is that the length of a well-structured programme is only a function of the number of unique operators and operands.
N=N1+N2
→ N^ stands for the estimated length of the programme.
→ N^ is equal to n1log2n1 + n2log2n2.
Alternative expressions for estimating programme duration have been published:
→ NJ is equal to log2 (n1!) + log2 (n2!)
→ NB = n1 * log2n2 + n2 * log2n1
→ NC = n1 * sqrt(n1) + n2 * sqrt(n2)
→ NS = (n * log2n) / 2
-
Minimum Volume Potential
The volume of the shortest programme in which a problem can be coded is denoted as the potential minimal volume V*.
V* = (2 + n2*) * log2 (2 + n2*)
n2* is the number of distinct input and output parameters.
-
The Size of Vocabulary (n)
The size of a program's vocabulary, which is comprised of the number of distinct tokens required to construct the programme, is defined as:
n=n1+n2
Where n denotes a program's vocabulary.
n1 denotes the number of distinct operators, while n2 denotes the number of separate operands.
Complexity Measures by Halstead
Howard Halstead pioneered the use of metrics to assess the complexity of software.
Halstead's metrics are based on the program's actual implementation and measures directly derived from the operators and operands in the source code.
It allows you to analyze C/C++/Java source code testing time, vocabulary, size, difficulty, errors, and attempts. Halstead metrics consider a programme a series of operators and their operands. He defines several measures to assess the module's difficulty.
- n1 The number of distinct operators
- n2 The number of separate operands
- N1 Total number of occurrences of operators
- N2 Total number of circumstances of operands
When we choose a source file in Metric Viewer to check its complexity data, we get the following result in Metric Report:
You can also check about Java Tokens here.
Advantages of Halstead’s Software Metrics
- Predicts the rate of mistake.
- Indicates the amount of work required for upkeep.
- The Calculation is simple.
- Assess the overall quality of the product.
- Any language can be used.
To know more about Software Engineering click here.
The Disadvantage of Halstead’s Software Metrics
- Complete code is required.
- As the programme level drops, the complexity rises.
- The Calculation is complex.
Frequently Asked Questions
-
What is the basis of Halstead’s Complexity measure?
Halstead's metrics are based on the program's actual implementation and measures directly derived from the operators and operands in the source code.
-
What does Halstead’s Volume metric represent?
It represents the amount of space required for storing the programme in bits.
-
What is Halstead’s effort?
Maurice Halstead devised a series of metrics to estimate the mental effort necessary to develop or maintain a programme, and Halstead's action is one of them.
-
What are process and project metrics?
Software process and project metrics are numerical measures that allow software engineers to get insight into the efficiency and use of the software process and the projects that are completed using the process framework.
Conclusion
In this article, we discussed Software Metrics, Requirements of Software Metrics, Halstead’s Software Metrics, Advantages and disadvantages of Halstead’s Software Metrics.
You can learn more about Quality Assurance at Software Quality Assurance, and you can also learn about Software Testing. To experience a virtual System Design interview, I suggest you check Top Interview questions.
You can also enrol in our courses on System Design to gain feedback on your design and get hands-on experience with system design.
We wish you Good Luck! Keep coding and keep reading Ninja!!