Unit IV

Software Metrics

Software metrics are quantitative measures used to assess the quality, complexity, and effort involved in software development. Halstead metrics are among the most widely studied.

📏 What are Software Metrics?

A software metric is a standard of measure used to quantify some property of a software system or its development process. They help predict effort, identify complexity, and improve quality.

Product Metrics
Size, Complexity, Quality
Process Metrics
Defect rates, productivity
Project Metrics
Cost, schedule, team size

🔢 Halstead Metrics

Proposed by Maurice Halstead (1977). Based on counts of operators and operands in source code — treats programs mathematically.

Basic Counts

SymbolMeaningExample
n1Number of distinct operators+, -, *, =, if, while …
n2Number of distinct operandsvariables, constants
N1Total occurrences of operatorssum of all operator uses
N2Total occurrences of operandssum of all operand uses
Halstead Derived Metrics — Formulas
Program Vocabulary (n) n = n1 + n2 Program Length (N) N = N1 + N2 Volume (V) V = N × log₂(n) Difficulty (D) D = (n1/2) × (N2/n2) Effort (E) E = D × V Time to Implement (T) T = E / 18 seconds

📐 Understanding Each Metric

Volume (V)

Measures the size of the implementation of an algorithm. The higher the volume, the more information the program contains. Measured in bits.

V = N × log₂(n) — N is program length, n is vocabulary size.

Program Length (N)

Total number of operator and operand occurrences in the program. This is the raw size measure.

Difficulty (D)

Measures how difficult the program is to write or understand. A program with many repeated operands and diverse operators has higher difficulty.

D = (n1/2) × (N2/n2)

Effort (E)

Total mental effort required to implement or understand the program.

E = D × V — proportional to both difficulty and volume.

🧮 Worked Example

Code Snippet
int z = x + y;
CountValueItems
n1 (distinct operators)3int, =, +
n2 (distinct operands)3z, x, y
N1 (total operators)3one each
N2 (total operands)3one each
n (vocabulary)6n1+n2
N (length)6N1+N2
V (volume)≈15.56 × log₂(6)
D (difficulty)1.5(3/2)×(3/3)
E (effort)≈23.31.5 × 15.5