The ABC software metric was introduced by Jerry Fitzpatrick in 1997 to overcome the drawbacks of the
LOC.
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
A branch, also called a ramus in botany, is a stem that grows off from another stem, or when structures like veins in leaves are divided into smaller veins.
History and etymology
In Old English, there are numerous words for branch, includi ...
(B), and number of
conditionals
Conditional (if then) may refer to:
*Causal conditional, if X then Y, where X is a cause of Y
*Conditional probability, the probability of an event A given that another event B
*Conditional proof, in logic: a proof that asserts a conditional, a ...
(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
Magnitude may refer to:
Mathematics
*Euclidean vector, a quantity defined by both its magnitude and its direction
*Magnitude (mathematics), the relative size of an object
*Norm (mathematics), a term for the size or length of a vector
*Order of ...
of the vector < Assignments (A), Branches (B), Conditionals (C) >, and is calculated as follows:
::
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 from Purdue University in 1975. He suggested that every computer program consists mainly of
tokens:
operators
Operator may refer to:
Mathematics
* A symbol indicating a mathematical operation
* Logical operator or logical connective in mathematical logic
* Operator (mathematics), mapping that acts on elements of a space to produce elements of another ...
and
operand
In mathematics, an operand is the object of a mathematical operation, i.e., it is the object or quantity that is operated on.
Unknown operands in equalities of expressions can be found by equation solving.
Example
The following arithmetic expres ...
s. 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
The function point is a "unit of measurement" to express the amount of business functionality an information system (as a product) provides to a user. Function points are used to compute a functional size measurement (FSM) of software. The cost (in ...
(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.
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.
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.
If the ABC vector is denoted as for a
subroutine
In computer programming, a function (also procedure, method, subroutine, routine, or subprogram) is a callable unit of software logic that has a well-defined interface and behavior and can be invoked multiple times.
Callable units provide a ...
, 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 .
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
In mathematics, orthogonality (mathematics), orthogonality is the generalization of the geometric notion of ''perpendicularity''. Although many authors use the two terms ''perpendicular'' and ''orthogonal'' interchangeably, the term ''perpendic ...
, 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
A weight function is a mathematical device used when performing a sum, integral, or average to give some elements more "weight" or influence on the result than other elements in the same set. The result of this application of a weight function is ...
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
Semantics is the study of linguistic Meaning (philosophy), meaning. It examines what meaning is, how words get their meaning, and how the meaning of a complex expression depends on its parts. Part of this process involves the distinction betwee ...
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.
ABC rules for C
The following rules give the count of Assignments, Branches, Conditionals in the ABC metric for
C:
# Add one to the assignment count when:
#* Occurrence of an assignment operator (=, *=, /=, %=, +=, -=, <<=, >>=, &=, !=, ^=).
#* Occurrence of an
increment or a decrement operator (++, --).
# Add one to branch count when:
#* Occurrence of a
function call
In computer programming, a function (also procedure, method, subroutine, routine, or subprogram) is a callable unit of software logic that has a well-defined interface and behavior and can be invoked multiple times.
Callable units provide a p ...
.
#* Occurrence of any
goto statement which has a target at a deeper level of
nesting than the level to the goto.
# 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++:
# 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.
# 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.
# 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
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
:
# 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) (++, --).
# Add one to branch count when
#* Occurrence of a function call or a class method call.
#* Occurrence of a ‘new’ operator.
# 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
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
In mathematics, the term ''linear'' is used in two distinct senses for two different properties:
* linearity of a '' function'' (or '' mapping'');
* linearity of a '' polynomial''.
An example of a linear function is the function defined by f(x) ...
, 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
*
Software complexity
*
Halstead complexity measures
*
Cyclomatic complexity
*
Synchronization complexity
*
Software metric
In software engineering and development, a software metric is a standard of measure of a degree to which a software system or process possesses some property. Even if a metric is not a measurement (metrics are functions, while measurements are t ...
References
External links
Applying the ABC Metric to C, C++, and Java{{Webarchive, url=https://web.archive.org/web/20180328004815/http://gmetrics.sourceforge.net/gmetrics-AbcMetric.html , date=2018-03-28
Deciphering Ruby Code MetricsThe ABC metric
Software metrics