Measuring system complexity 1-3


发布时间:2017-03-23 来源:本站原创 作者:本站编辑   


Measuring system complexity

lines-of-code (LOC)

·      Several techniques have been developed for the measurement of system complexity and their use in object-oriented systems.

 

·      Note: the application of metrics to object-oriented systems is still not universally accepted.

·      Lines-of-code metric

o  A very simple measure of the complexity of a system description is given by counting the number of lines in the description - lines-of-code (LOC) metric.

 

·      Needs careful definition - should comment lines be included

 

·      The COCOMO method uses the LOC metric for estimating person-years of effort in system development.

o  But LOC itself needs to be estimated first!

o  Also takes no account of algorithm complexity – 6 nested ‘if then else’ is generally core complex that than LOC indicates.


 

Cyclomatic-Complexity

 

·      A flow graph can be used to represent the structure of a  program – see below.

 

·      Each letter represents statements as set of sequential statements in the program. Nodes represent branches in execution.

 

 

 

 


 

 

·      McCabe’s cyclomatic-complexity metric measures the complexity of a method by counting the number of independent paths through a method body.

 

·      A path is a trace of the statements in the method actually executed -ignoring all iterations except the first e.g a,b,d,h,k

 

·      Two paths are independent if they differ in at least one statement or expression.

 

·      The cyclomatic-complexity is calculated by summing the decision points and adding 1.

 

·      In the above example:  3 + 1 = 4


 

 

·      The cyclomatic-complexity metric has been found to be an accurate predictor of the number of errors in method bodies.

 

·      The higher the complexity as predicted by the cyclomatic-complexity metric, the higher the likelihood of errors.

 

·      As a simple rule of thumb, a cyclomatic complexity of 10 or more is a hint that a method body is too complex.

 

·      Chidamber and Kemerer (1994) have provided a suite of complexity metrics for use specifically with object-oriented systems.

 

·      Weighted-methods-per-class (WMPC) metric

 

·      It is defined as the sum of the cyclomatic complexities of each method of the class.