Puneet Varma (Editor)

ABC score

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

The ABC software 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.

Contents

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

| < A B C S c o r e > | = ( A 2 + B 2 + C 2 )

ABC magnitude value should be rounded off to the nearest tenth.

History

The concept of measuring software size was first introduced by Maurice Halstead 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.

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 and about the routines that were involved in the program.

The ABC score was thus introduced by Jerry Fitzpatrick in 1997 to overcome the drawbacks of the LOC, FP and measure of program size by tokens (operations and operands). However, FP can be used in addition to the ABC score instead of as a replacement.

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.

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. The standardized notation <A, B, C> suggests one to always write the counts in the same order and only use angle brackets to enclose the counts.

To compare ABC counts of two different codes, it is important to use only one scalar measurement. So, since the components of the ABC vector may not be related and are completely distinct we cannot add them directly to get a good scalar metric. As per Jerry Fitzpatrick, we can assume the three vector components to be orthogonal. We can now calculate the magnitude of ABC vector as defined above.

It may be shown that scalar values are not good comparable metrics. A better scalar metric may be obtained if weighted sum is performed on the vectors instead of assuming the vectors to be orthogonal and calculating the magnitude. ABC scalar metric should not be presented without the accompanying ABC vector because the scalar numbers might not be the complete representation of the size of the subroutine.

Theory

The specific rules for counting ABC vector values should be interpreted differently for different languages because of the semantic difference between the programming languages.

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.

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

Independent of style of coding

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 score 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’. ABC vector metric can give us insights about the driving principles behind the application unlike the scalar number which does not provide this information.

Linear metric

ABC metric is linear, and therefore, any file, module, class, function or method can be given an ABC metric value. The ABC vector value for the complete module is the sum of ABC vectors of all its sub-modules. However, the ABC scalar values are not linear.

References

ABC score Wikipedia