ABC Software Metric

From HandWiki

The ABC software metric was introduced by Jerry Fitzpatrick in 1997 to overcome the drawbacks of the LOC.[1] The metric defines an ABC score as a triplet of values that represent the size of a set of source code statements. An ABC score is calculated by counting the number of assignments (A), number of branches (B), and number of conditionals (C) in a program. ABC score can be applied to individual methods, functions, classes, modules or files within a program.

ABC score is represented by a 3-D vector < Assignments (A), Branches (B), Conditionals (C) >. It can also be represented as a scalar value, which is the magnitude of the vector < Assignments (A), Branches (B), Conditionals (C) >, and is calculated as follows:

[math]\displaystyle{ |\lt \mathrm{ABCvector}\gt | = \surd(A^2 + B^2 + C^2) }[/math]

By convention, an ABC magnitude value is rounded to the nearest tenth.

History

The concept of measuring software size was first introduced by Maurice Halstead[2] from Purdue University in 1975. He suggested that every computer program consists mainly of tokens: operators and operands. He concluded that a count of the number of unique operators and operands gives us a measure of the size of the program. However, this was not adopted as a measure of the size of a program.

Lines of code (LOC) was another popular measure of the size of a program. The LOC was not considered an accurate measure of the size of the program because even a program with identical functionality may have different numbers of lines depending on the style of coding.[3]

Another metric called the Function Point (FP) metric was introduced to calculate the number of user input and output transactions. The function point calculations did not give information about both the functionality of the program nor about the routines that were involved in the program.[4]

The ABC metric is intended to overcome the drawbacks of the LOC, FP and token (operation and operand) counts. However, an FP score can also be used to supplement an ABC score.

Though the author contends that the ABC metric measures size, some believe that it measures complexity.[5] The ability of the ABC metric to measure complexity depends on how complexity is defined.

Definition

The three components of the ABC score are defined as following:

  • Assignment: storage or transfer of data into a variable.
  • Branches: an explicit forward program branch out of scope.
  • Conditionals: Boolean or logic test.

Since basic languages such as C, C++, Java, etc. have operations like assignments of variables, function calls and test conditions only, the ABC score has these three components.[1]

If the ABC vector is denoted as ⟨5,11,9⟩ for a subroutine, it means that the subroutine has 5 assignments, 11 branches and 9 conditionals. For standardization purposes, the counts should be enclosed in angle brackets and written in the same order per the notation ⟨A, B, C⟩.

It is often more convenient to compare source code sizes using a scalar value. The individual ABC counts are distinct so, per Jerry Fitzpatrick, we consider the three components to be orthogonal, allowing a scalar ABC magnitude to be computed as shown above.

Scalar ABC scores lose some of the benefits of the vector. Instead of computing a vector magnitude, the weighted sum of the vectors may support more accurate size comparison. ABC scalar scores should not be presented without the accompanying ABC vectors, since the scalar values are not the complete representation of the size.

Theory

The specific rules for counting ABC vector values should be interpreted differently for different languages due to semantic differences between them.

Therefore, the rules for calculating ABC vector slightly differ based on the language. We define the ABC metric calculation rules for C, C++ and Java below. Based on these rules the rules for other imperative languages can be interpreted.[1]

ABC rules for C

The following rules give the count of Assignments, Branches, Conditionals in the ABC metric for C:

  1. Add one to the assignment count when:
  2. Add one to branch count when:
    • Occurrence of a function call.
    • Occurrence of any goto statement which has a target at a deeper level of nesting than the level to the goto.
  3. Add one to condition count when:
    • Occurrence of a conditional operator (<, >, <=, >=, ==, !=).
    • Occurrence of the following keywords (‘else’, ‘case’, ‘default’, ‘?’).
    • Occurrence of a unary conditional operator.

ABC rules for C++

The following rules give the count of Assignments, Branches, Conditionals in the ABC metric for C++:

  1. Add one to the assignment count when:
    • Occurrence of an assignment operator (exclude constant declarations and default parameter assignments) (=, *=, /=, %=, +=, -=, <<=, >>=, &=, !=, ^=).
    • Occurrence of an increment or a decrement operator (prefix or postfix) (++, --).
    • Initialization of a variable or a nonconstant class member.
  2. Add one to branch count when:
    • Occurrence of a function call or a class method call.
    • Occurrence of any goto statement which has a target at a deeper level of nesting than the level to the goto.
    • Occurrence of ‘new’ or ‘delete’ operators.
  3. Add one to condition count when:
    • Occurrence of a conditional operator (<, >, <=, >=, ==, !=).
    • Occurrence of the following keywords (‘else’, ‘case’, ‘default’, ‘?’, ‘try’, ‘catch’).
    • Occurrence of a unary conditional operator.

ABC rules for Java

The following rules give the count of Assignments, Branches, Conditionals in the ABC metric for Java:

  1. Add one to the assignment count when:
    • Occurrence of an assignment operator (exclude constant declarations and default parameter assignments) (=, *=, /=, %=, +=, -=, <<=, >>=, &=, !=, ^=, >>>=).
    • Occurrence of an increment or a decrement operator (prefix or postfix) (++, --).
  2. Add one to branch count when
    • Occurrence of a function call or a class method call.
    • Occurrence of a ‘new’ operator.
  3. Add one to condition count when:
    • Occurrence of a conditional operator (<, >, <=, >=, ==, !=).
    • Occurrence of the following keywords (‘else’, ‘case’, ‘default’, ‘?’, ‘try’, ‘catch’).
    • Occurrence of a unary conditional operator.

Applications

[1]

Independent of coding style

Since the ABC score metric is built on the idea that tasks like data storage, branching and conditional testing, this metric is independent of the user's style of coding.

Project time estimation

ABC score calculation helps in estimating the amount of time needed to complete a project. This can be done by roughly estimating the ABC score for the project, and by calculating the ABC score of the program in a particular day. The amount of time taken for the completion for the project can be obtained by dividing the ABC score of the project by the ABC score achieved in one day.

Bug rate calculation

The bug rate was originally calculated as Number of bugs / LOC. However, the LOC is not a reliable measure of the size of the program because it depends on the style of coding. A more accurate way of measuring bug rate is to count the - Number of bugs / ABC score.

Program comparison

Programs written in different languages can be compared with the help of ABC scores because most languages use assignments, branches and conditional statements.

The information on the count of the individual parameters (number of assignments, branches and conditions) can help classify the program as ‘data strong’ or ‘function strong’ or ‘logic strong’. The vector form of an ABC score can provide insight into the driving principles behind the application, whereas the details are lost in the scalar form of the score.

Linear metric

ABC scores are linear, so any file, module, class, function or method can be scored. For example, the (vector) ABC score for a module is the sum of the scores of its sub-modules. Scalar ABC scores, however, are non-linear.

See also

References

  1. 1.0 1.1 1.2 1.3 Fitzpatrick, Jerry (1997). "Applying the ABC metric to C, C++ and Java". C++ Report. https://www.win.tue.nl/~wstomv/edu/2ip30/references/ABCmetric.pdf. 
  2. Halstead, Maurice (1977). Elements of Software Science. North Holland: Elsevier. 
  3. Fenton, Norman E. (1991). "Software Metrics: Successes, Failures and New Directions". Chapman & Hall. https://www.agileconnection.com/sites/default/files/article/file/2014/Software%20Metrics-%20Successes,%20Failures,%20and%20New%20Directions.pdf. 
  4. Kitchenham, Barbara (December 1995). "Towards a Framework for Software Measurement Validation". IEEE Transactions on Software Engineering 21 (12): 929–944. doi:10.1109/32.489070. 
  5. Fitzpatrick, Jerry (2017). "Appendix A". Timeless Laws of Software Development. Software Renovation Corporation. ISBN 978-0999335604. 

External links