Software Metrics II

Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

Sequential Search

Binary Search

Search

Complexity

  • More complex implies:
  • More difficult to develop from requirements
  • More difficult to comprehend
  • More difficult to evolve (new features or pure maintenance)
  • Note: Binary search first mentioned in 1946, dealing with when N is not of the form 2n - 1 was not published until 1960

Complexity Measures

  • LOC is a form of complexity but doesn't take into consideration everything that contributes to the complexity
  • May want to look at the operations taking place, and the type of statements

Halstead Complexity Measure

  • Example if (k < 2) { if (k > 3) x = x * k; }

  • Operators: if, (, ), {, }, <, >, =, *, ;
  • Operands: k, 2, 3, x

  • Number of Distinct Operators: n1
  • Number of Distinct Operands: n2
  • Total Operators: N1
  • Total Operands: N2

Halstead Measure Example

  • Program vocabulary: n = n1 + n2
  • Program length: N = N1 + N2
  • Calculated program length: n1 log2 n1 + n2 log2 n2
  • Volume: V = N * log2 n
  • Difficulty: D = ( n1 / 2 ) * ( N2 / n2 )
  • Effort: E = D * V

Halstead Measure Analysis

  • So, is this useful?
  • Correlates to LOC very well

Cyclomatic Complexity

  • McCabe's complexity measure
  • Calculation of the number of linearly independent paths through the code
  • Provides the minimum number of test cases for complete code coverage (execute all lines of code at least once)

Cyclomatic Complexity

  • Easy calculation: Number of conditions + 1
  • AKA Conditional Complexity
  • Potential for strong relation to cohesion

Object-Oriented Metrics

  • Chidamber & Kemerer'94 TSE (IEEE Transactions on Software Engineering)
  • Specifically for OO software
  • Direct measures of class-oriented metrics

Chidamber & Kemerer Metrics

  • WMC -Weighted Methods per Class
  • DIT - Depth of Inheritance Tree
  • NOC - Number of Children
  • CBO - Collaborations between classes
  • RFC - Response for a class
  • LCOM - Lack of Cohesion in Methods
  • CS - Class Size
  • NOO - Number of Operations Overridden
  • NOA - Number of Operations Added
  • MIF -Method Inheritance Factor
  • CF - Coupling Factor
  • Polymorphism Factor

Application of Metrics

  • What are we using the metric for?
  • One metric is often not enough, even for a single purpose
  • Metrics tools often generate an entire, often different, suite of metrics
  • Not all metrics tools will give the same result, so a comparison between tools can be a problem