TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Software Engineering | Halstead's Software Metrics

Software Engineering | Halstead's Software Metrics with software engineering tutorial, models, engineering, software development life cycle, sdlc, requirement engineering, waterfall model, spiral model, rapid application development model, rad, software management, etc.

<< Back to SOFTWARE

Halstead's Software Metrics

According to Halstead's "A computer program is an implementation of an algorithm considered to be a collection of tokens which can be classified as either operators or operand."

Token Count

In these metrics, a computer program is considered to be a collection of tokens, which may be classified as either operators or operands. All software science metrics can be defined in terms of these basic symbols. These symbols are called as a token.

The basic measures are

n1 = count of unique operators.
n2 = count of unique operands.
N1 = count of total occurrences of operators.
N2 = count of total occurrence of operands.

In terms of the total tokens used, the size of the program can be expressed as N = N1 + N2.

Halstead metrics are:

Program Volume (V)

The unit of measurement of volume is the standard unit for size "bits." It is the actual size of a program if a uniform binary encoding for the vocabulary is used.

        V=N*log2n

Program Level (L)

The value of L ranges between zero and one, with L=1 representing a program written at the highest possible level (i.e., with minimum size).

        L=V*/V

Program Difficulty

The difficulty level or error-proneness (D) of the program is proportional to the number of the unique operator in the program.

        D= (n1/2) * (N2/n2)

Programming Effort (E)

The unit of measurement of E is elementary mental discriminations.

        E=V/L=D*V

Estimated Program Length

According to Halstead, The first Hypothesis of software science is that the length of a well-structured program is a function only of the number of unique operators and operands.

        N=N1+N2

And estimated program length is denoted by N^

        N^ = n1log2n1 + n2log2n2

The following alternate expressions have been published to estimate program length:

  • NJ = log2 (n1!) + log2 (n2!)
  • NB = n1 * log2n2 + n2 * log2n1
  • NC = n1 * sqrt(n1) + n2 * sqrt(n2)
  • NS = (n * log2n) / 2

Potential Minimum Volume

The potential minimum volume V* is defined as the volume of the most short program in which a problem can be coded.

        V* = (2 + n2*) * log2 (2 + n2*)

Here, n2* is the count of unique input and output parameters

Size of Vocabulary (n)

The size of the vocabulary of a program, which consists of the number of unique tokens used to build a program, is defined as:

        n=n1+n2

where

n=vocabulary of a program
n1=number of unique operators
n2=number of unique operands

Language Level - Shows the algorithm implementation program language level. The same algorithm demands additional effort if it is written in a low-level program language. For example, it is easier to program in Pascal than in Assembler.

        L' = V / D / D
lambda = L * V* = L2 * V

Language levels

Language Language level λ Variance σ
PL/1 1.53 0.92
ALGOL 1.21 0.74
FORTRAN 1.14 0.81
CDC Assembly 0.88 0.42
PASCAL 2.54 -
APL 2.42 -
C 0.857 0.445

Counting rules for C language

  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 like return, default, continue, break, sizeof, etc., are considered as operators.
  10. All the brackets, commas, and terminators are considered as operators.
  11. GOTO is counted as an operator, and the label is counted as an operand.
  12. The unary and binary occurrence of "+" and "-" are dealt with separately. Similarly "*" (multiplication operator) are dealt separately.
  13. In the array variables such as "array-name [index]" "array-name" and "index" are considered as operands and [ ] is considered an operator.
  14. In the structure variables such as "struct-name, member-name" or "struct-name -> member-name," struct-name, member-name are considered as operands and '.', '->' are taken as operators. Some names of member elements in different structure variables are counted as unique operands.
  15. All the hash directive is ignored.

Example: Consider the sorting program as shown in fig: List out the operators and operands and also calculate the value of software science measure like n, N, V, E, λ ,etc.

Solution: The list of operators and operands is given in the table

Operators Occurrences Operands Occurrences
int 4 SORT 1
() 5 x 7
, 4 n 3
[] 7 i 8
if 2 j 7
< 2 save 3
; 11 im1 3
for 2 2 2
= 6 1 3
- 1 0 1
<= 2 - -
++ 2 - -
return 2 - -
{} 3 - -
n1=14 N1=53 n2=10 N2=38

Here N1=53 and N2=38. The program length N=N1+N2=53+38=91

Vocabulary of the program n=n1+n2=14+10=24

Volume V= N * log2N=91 x log2 24=417 bits.

The estimate program length N of the program

                = 14 log214+10 log2)10
                = 14 * 3.81+10 * 3.32
                = 53.34+33.2=86.45

Conceptually unique input and output parameters are represented by n2*.

        n2*=3 {x: array holding the integer to be sorted. This is used as both input and output}

                {N: the size of the array to be sorted}

The Potential Volume V*=5log25=11.6

Since         L=V*/V

Halstead's Software Metrics

We may use another formula

                V^=V x L^= 417 x 0.038=15.67
                E^=V/L^=D^ x V Halstead's Software Metrics

Therefore, 10974 elementary mental discrimination is required to construct the program.

Halstead's Software Metrics

This is probably a reasonable time to produce the program, which is very simple.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf