Software Measurement Halsteads Software Science measure 18 1

  • Slides: 12
Download presentation
Software Measurement Halstead’s Software Science measure 18 1

Software Measurement Halstead’s Software Science measure 18 1

Maurice Halstead u Originally a meteorologist – Involved in first cloud seeding u In

Maurice Halstead u Originally a meteorologist – Involved in first cloud seeding u In 1970’s he did empirical studies looking for relationships between code and the “ilities” – maintainability, readability, testability, etc u Wanted to find the intrinsic things to measure 18 2

Vs Physics Study blue metal balls vs white tennis balls. Conclude that blue balls

Vs Physics Study blue metal balls vs white tennis balls. Conclude that blue balls made bigger dents than white balls. measure 18 3

Halstead's software science u every token is either an operator or an operand u

Halstead's software science u every token is either an operator or an operand u tokens with a value are operands § 2 is the number of unique operands u other tokens are operators § 1 is the number of unique operators u is the total number of unique tokens § = 1 + 2 measure 18 4

Sample Program Z = 0; while X > 0 Z=Z+Y; X=X-1; end-while ; print

Sample Program Z = 0; while X > 0 Z=Z+Y; X=X-1; end-while ; print (Z) ; measure 18 5

Counts u= 3 u; 5 u while-endwhile 1 u> 1 u+ 1 u print

Counts u= 3 u; 5 u while-endwhile 1 u> 1 u+ 1 u print 1 u () 1 measure 18 u. Z u 0 u. X u. Y u 1 4 2 3 1 1 6

Counting Rules u Halstead also was concerned about algorithms and not about declarations, i/o

Counting Rules u Halstead also was concerned about algorithms and not about declarations, i/o statements, etc. u Thus, he did not count declarations, input or output statements, or comments. measure 18 7

Counting Rules u There is a lot of debate about counting rules. In fact

Counting Rules u There is a lot of debate about counting rules. In fact there was a conference that dealt just with counting rules. One conclusion, the results are not very sensitive to the counting rules. Pick a set of rules and be consistent. u Suggest syntax-oriented counting rules measure 18 8

Counting Rules u if two symbols always occur together, count them as one operator.

Counting Rules u if two symbols always occur together, count them as one operator. u if there are two different structures that are semantically the same, still count them as two different operators. u count declarations, i/o, etc. Count everything that is necessary for expressing the program. u operators are basically keywords. user-defined items are basically operands. measure 18 9

Length, N u. N = N 1 + N 2 u where, N 1

Length, N u. N = N 1 + N 2 u where, N 1 is the total number of operators and N 2 is the total number of operands measure 18 10

estimate of the length, est N u If N and est N are not

estimate of the length, est N u If N and est N are not within 30% of each other, it is not reasonable to apply any of the other software science measures. measure 18 11

TTYP 1 - Calculate Halstead’s cin >> a >> b >> c; if (a

TTYP 1 - Calculate Halstead’s cin >> a >> b >> c; if (a > b){ cout << “hello”; if (c < a){cout << “part 1”; if ( c > b){cout << “part 2”; } } else{ cout << “part 3”; } } else{if (c<a){cout<<”part 4”; } } cout << “exiting”; measure 18 12