请输入您要查询的百科知识:

 

词条 Halstead complexity measures
释义

  1. Calculation

  2. Example

  3. See also

  4. References

  5. External links

{{short description|Software maintainability index}}

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

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 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 {{Citation needed||reason='By whom?'|date=August 2013}}.

Example

Let us 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 unique operators are:

main, (), {}, int, scanf,

&, =, +, /, printf, ',', ;

The unique 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

  • Function point
  • Cyclomatic complexity

References

1. ^{{cite book |author=Halstead, Maurice H. |title=Elements of Software Science |publisher=Elsevier North-Holland, Inc. |location=Amsterdam |year=1977 |isbn=0-444-00205-7}}

External links

  • The Halstead metrics - Extensive discussion on the calculation and use of Halstead Metrics in an object-oriented environment (with specific reference to Java).
  • Calculation of Halstead metrics - Measurement of Halstead Metrics.
  • Explanation with a Sample Program - Example (on Page 6 of the PDF)
  • [https://github.com/dborowiec/commentedCodeDetector Script computing Halstead Metrics and using them for commented code detection]
  • IBM

1 : Software metrics

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/13 12:16:19