HALSTEAD SOFTWARE SCIENCE MEASURES A PROGRAM IS CONSIDERED TO BE SERIES OF TOKEN TOKENS ARE CLASSIFIED INTO OPERATORS AND OPERANDS OIN A PROGRAM Token Count ŋ = ŋ 1+ ŋ 2 ŋ : vocabulary of a program ŋ 1 : number of unique operators ŋ 2 : number of unique operands Length of the program The length of the program in the terms of the total number of tokens used is N = N1+N2 N : program length N1 : total occurrences of operators N2 : total occurrences of operands
Program volume (v) The program volume (V) is the information contents of the program, measured in mathematical bits. It is calculated as the Program length times the 2-base logarithm of the vocabulary size V = N * log2(ŋ) Difficult level The difficulty level or error proneness (D) of the program is proportional to the number of unique operators in the program. D = ( ŋ1 / 2 ) * ( N2 / ŋ2 )
Program level (L ) The program level (L) is the inverse of the error proneness of the program. I.e. a low level program is more prone to errors than a high level program. L = 1 / D Effort to implement (E) The effort to implement (E) or understand a program is proportional to the volume and to the difficulty level of the program. E = V * D
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. the estimated length is denoted by N^ N^= ŋ1log2ŋ1+ ŋ2log2ŋ2 Potential Volume : Amongst all the programs, the one that has minimal size is said to have the potential volume, V*. V*= (2+ŋ2*) log2( 2+ŋ2*)
Estimated program Level/difficulty Halstead offered an alternate formula that estimates the program level. L^ =2ŋ2/ŋ1N2 Hence, D =1 /L^ Effort: Halstead hypothesized that the effort required to implement a program increases as the size of the program increases. It takes more effort to implement a program at a lower level than the higher level. E= V/L^
#include< stdio.h > #define MAXLINE 100 Int getline (char line[], int max); Char strindex (char source[],char search for[]); Char pattern[ ]=“ ould ” Int main() { Char line =[MAXLINE]; Int found =0; While( getline ( line,pattern )>0) If( strindex ( line,pattern )>=0) { printf (“% s”,line ); Found++; } Return found; } c program
Int getline (char s[], int lim ) { Int c,i =0; While(-- lim >0&&(c= getchar ())!=EOF && c!=‘\n’) S[ i ++]=c; If(c==‘\n’) S[ i ]=‘\0’; Return I; } Int strindex (char s[],char t[]) { Int I,j,k ; For( i =0;s[ i ] !=‘/0’;i++) If(k>0 && t[k]==‘\0’) Return I; } Return -1; }
List of operators and operands OPERATORS OCURRENCES OPERANDS OCCURENCES MAIN() 1 - - - 1 EXTERN VARIABLE PATTERN 1 FOR 2 MAIN FUNCTION LINE 3 = = 3 FOUND 2 != 4 GETLINE FUNCTION S 3 GETCHAR 1 LIM 1 () 1 C 5 && 3 I 4