For faster navigation, this Iframe is preloading the Wikiwand page for Halstead complexity measures.

Halstead complexity measures

Halstead complexity measures are software metrics introduced by Maurice Howard Halstead in 1977[1] as part of his treatise on establishing an empirical science of software development. Halstead made the observation that metrics of the software should reflect the implementation or expression of algorithms in different languages, but be independent of their execution on a specific platform. These metrics are therefore computed statically from the code.

Halstead's goal was to identify measurable properties of software, and the relations between them. This is similar to the identification of measurable properties of matter (like the volume, mass, and pressure of a gas) and the relationships between them (analogous to the gas equation). Thus his metrics are actually not just complexity metrics.

Calculation

[edit]

For a given problem, let:

  • = the number of distinct operators
  • = the number of distinct operands
  • = the total number of operators
  • = the total number of operands

From these numbers, several measures can be calculated:

  • Program vocabulary:
  • Program length:
  • Calculated estimated program length:
  • Volume:
  • Difficulty :
  • Effort:

The difficulty measure is related to the difficulty of the program to write or understand, e.g. when doing code review.

The effort measure translates into actual coding time using the following relation,

  • Time required to program: seconds

Halstead's delivered bugs (B) is an estimate for the number of errors in the implementation.

  • Number of delivered bugs : or, more recently, is accepted.[1]

Example

[edit]

Consider the following C program:

main()
{
  int a, b, c, avg;
  scanf("%d %d %d", &a, &b, &c);
  avg = (a+b+c)/3;
  printf("avg = %d", avg);
}

The distinct operators () are: main, (), {}, int, scanf, &, =, +, /, printf, ,, ;

The distinct operands () are: a, b, c, avg, "%d %d %d", 3, "avg = %d"

  • , ,
  • , ,
  • Calculated Estimated Program Length:
  • Volume:
  • Difficulty:
  • Effort:
  • Time required to program: seconds
  • Number of delivered bugs:

See also

[edit]

References

[edit]
  1. ^ a b Halstead, Maurice H. (1977). Elements of Software Science. Amsterdam: Elsevier North-Holland, Inc. ISBN 0-444-00205-7.
[edit]
{{bottomLinkPreText}} {{bottomLinkText}}
Halstead complexity measures
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?