[go: nahoru, domu]

Jump to content

Essential complexity: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Add of an url to the NIST, in order to ease the understanding and the computing of the essential complexity
sentence completed with "and then do not increase the essential cyclomatic complexity"
Line 11: Line 11:
== Cyclomatic complexity ==
== Cyclomatic complexity ==
{{main|Cyclomatic complexity}}
{{main|Cyclomatic complexity}}
'''Essential complexity''' is also used with a different meaning in connection with [[cyclomatic complexity]]. In this context, essential complexity refers to the cyclomatic complexity after iteratively replacing all well structured control structures with a single statement. Structures such as if-then-else and while loops are considered well structured. Unconstrained use of goto statements can produce programs which can not be reduced in this way.
'''Essential complexity''' is also used with a different meaning in connection with [[cyclomatic complexity]]. In this context, essential complexity refers to the cyclomatic complexity after iteratively replacing all well structured control structures with a single statement. Structures such as if-then-else and while loops are considered well structured and then do not increase the essential cyclomatic complexity. Unconstrained use of goto, break and continue statements can produce programs which can not be reduced in this way.


For example, the following C program fragment has an essential complexity of 1, because the inner '''if''' statement and the '''for''' can be reduced:
For example, the following C program fragment has an essential complexity of 1, because the inner '''if''' statement and the '''for''' can be reduced:
Line 23: Line 23:
for(i=0;i<m;i++) {
for(i=0;i<m;i++) {
for(j=0;j<n;j++) {
for(j=0;j<n;j++) {
if(z[i][j] != 0) goto non_zero;
if(z[i][j] != 0) '''goto non_zero''';
}
}
goto found;
'''goto found''';
non_zero:
non_zero:
}
}

Revision as of 09:24, 14 September 2012

Essential complexity refers to a situation where all reasonable solutions to a problem must be complicated (and possibly confusing) because the "simple" solutions would not adequately solve the problem. It stands in contrast to accidental complexity, which arises purely from mismatches in the particular choice of tools and methods applied in the solution.

This term has been used since, at least, the mid-1980s. Turing Award winner Fred Brooks has used this term and its antonym of accidental complexity since the mid-1980s. He has also updated his views in 1995 for an anniversary edition of Mythical Man-Month, chapter 17 "'No Silver Bullet' Refired".[1][2][3] [4]


Cyclomatic complexity

Essential complexity is also used with a different meaning in connection with cyclomatic complexity. In this context, essential complexity refers to the cyclomatic complexity after iteratively replacing all well structured control structures with a single statement. Structures such as if-then-else and while loops are considered well structured and then do not increase the essential cyclomatic complexity. Unconstrained use of goto, break and continue statements can produce programs which can not be reduced in this way.

For example, the following C program fragment has an essential complexity of 1, because the inner if statement and the for can be reduced:

  for(i=0;i<3;i++) {
     if(a[i] == 0) b[i] += 2;
  }

The following C program fragment has an essential complexity of more than one. It finds the first row of z which is all zero and puts that index in i; if there is none, it puts -1 in i.

      for(i=0;i<m;i++) {
          for(j=0;j<n;j++) {
              if(z[i][j] != 0) goto non_zero;
          }
          goto found;
  non_zero:
      }
      i = -1;
  found:

See also

Further reading

  • Brooks, Fred P. (1986). "No Silver Bullet - Essence and Accident in Software Engineering". Proceedings of the IFIP Tenth World Computing Conference: 1069–1076.
  • Brooks, Fred P. (April 1987). "No Silver Bullet - Essence and Accidents of Software Engineering". IEEE Computer. 20 (4): 10–19. {{cite journal}}: Unknown parameter |authormask= ignored (|author-mask= suggested) (help)
  • Brooks, Fred P. (1995). "Chap. 17". 'No Silver Bullet' Refired (Anniversary Edition with four new chapters ed.). Addison-Wesley. ISBN 0-201-83595-9. {{cite book}}: |work= ignored (help); Unknown parameter |authormask= ignored (|author-mask= suggested) (help)

References

  1. ^ Brooks, Proc. IFIP
  2. ^ Brooks, IEEE Computer
  3. ^ Brooks, Mythical Man-Month, Silver Bullet Refired
  4. ^ McCabe, Watson (1996). "Structured Testing: A Testing Methodology Using the Cyclomatic Complexity Metric Chapter 10: Essential Complexity".