What cannot be measured cannot be controlled. Software metrics give numbers that help to plan, estimate and judge a project.

Need and Benefits of Metrics

A software metric is a quantitative measure of some property of the software or its process. Metrics are needed to estimate cost and time, to control the project by comparing the actual with the plan, to assess quality, to find the weak parts of the process, and to compare projects. The benefits are better planning, early warning of problems, objective decisions and improvement of the process over time. Metrics are of three kinds. Product metrics measure the software, such as size and complexity. Process metrics measure the development process, such as defects found per phase. Project metrics measure the project, such as effort and cost.

Definition: Software metric. A quantitative measure of the degree to which a software product, process or project possesses some property.

Size Metrics: Lines of Code

Lines of code (LOC), or thousands of lines of code (KLOC), is the simplest size measure. It is easy to count and is used in estimation models. Its drawbacks are that it depends on the language and the style of programming, it cannot be known until coding is finished, and it rewards long programs instead of good ones. A line may mean a physical line or a statement, and comments may or may not be counted, so the rule must be defined.

Token Count (Halstead's Measure)

The token count treats a program as a series of operators and operands. Let n1 and n2 be the number of distinct operators and operands, and N1 and N2 their total occurrences. The vocabulary n = n1 + n2 and the length N = N1 + N2. The volume V = N log2(n) measures the size in bits. The estimated length is N-hat = n1 log2(n1) + n2 log2(n2). This measure does not depend on the style of layout, but it can be found only after the code is written.

Function Point Metric

Function points (FP) measure the size from the point of view of the user, and do not depend on the language. The five information domain items are external inputs (EI), external outputs (EO), external inquiries (EQ), internal logical files (ILF) and external interface files (EIF). Each is counted and given a weight of simple, average or complex. The sum is the unadjusted function point (UFP) count. A value adjustment factor VAF = 0.65 + 0.01 × (sum of 14 ratings, each from 0 to 5) is applied. Then FP = UFP × VAF. The average weights are 4 for EI, 5 for EO, 4 for EQ, 10 for ILF and 7 for EIF.

Table 2.6: Average weights of function point items

Item Meaning Average weight
External input (EI) Data entering the system 4
External output (EO) Reports leaving the system 5
External inquiry (EQ) Query with an immediate reply 4
Internal logical file (ILF) Data kept by the system 10
External interface file (EIF) Data from other systems 7

Example 2.6: Computing function points

Problem: A system has 10 EI, 8 EO, 5 EQ, 4 ILF and 2 EIF, all with average weights. The sum of the 14 ratings is 42. Find the function points.

Solution:

  1. UFP = 10 × 4 + 8 × 5 + 5 × 4 + 4 × 10 + 2 × 7 = 40 + 40 + 20 + 40 + 14 = 154.
  2. VAF = 0.65 + 0.01 × 42 = 1.07.
  3. FP = 154 × 1.07.

Result: FP = 164.78, about 165 function points.

import math
ufp = 10 * 4 + 8 * 5 + 5 * 4 + 4 * 10 + 2 * 7
vaf = 0.65 + 0.01 * 42
print(ufp, round(vaf, 2), round(ufp * vaf, 2))
n1, n2, N1, N2 = 10, 8, 40, 30
print(round((N1 + N2) * math.log2(n1 + n2), 1))

Output

154 1.07 164.78
291.9

Common mistakes

  • Using LOC to compare programs written in different languages.
  • Counting data files and reports as the same kind of function point item.
  • Forgetting the value adjustment factor.

Key takeaways

  • Metrics are used to estimate, control and improve.
  • LOC is easy but depends on the language.
  • Halstead's volume V = N log2(n).
  • FP = UFP × VAF, with VAF = 0.65 + 0.01 × the sum of the 14 ratings.

Practice questions

  1. Name the three kinds of metrics.
  2. Give one drawback of LOC.
  3. Write the formula for function points.

Answers to the practice questions

  1. Product, process and project metrics.
  2. It depends on the language and style, and is known only after coding.
  3. FP = UFP × VAF.

Sources

  • Official BCA syllabus Advanced Software Engineering, course code 25BCA405DS01, Unit II