Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 50 ยท Quality, Testing and Delivery

Software Metrics: Product, Process and People

Learn software measurement: product metrics (size, fan-in/fan-out, nesting depth, fog index), process metrics (defect density, lead time) and people metrics, with runnable code.

"You cannot control what you cannot measure" is only half true: you can also be misled by what you measure. Software measurement is the practice of giving numbers to attributes of software, of the process that builds it and of the people who build it, so that decisions rest on evidence instead of mood.

A few terms first. A measure is a single data point (this file has 240 lines). A metric relates measures to an attribute (defects per thousand lines). An indicator is a metric used to judge something (defect density above the agreed limit). A good metric is simple to compute, understandable, objective, consistent, applicable to decisions and economical to collect.

Software metrics fall into three groups: product metrics, process metrics and people (project) metrics. The examples below are plain JavaScript with invented data.

Product metrics

Product metrics describe the software itself. They split into static metrics, computed from the code or design without running it, and dynamic metrics, collected while it runs.

Kind Examples
Static Lines of code, cyclomatic complexity, fan-in/fan-out, depth of conditional nesting, comment density, fog index of documentation
Dynamic Response time, throughput, memory use, failure rate, mean time between failures (MTBF)

Size: lines of code

LOC is easy to count and easy to abuse. It says nothing about quality and varies by language. Use it to normalize other metrics (defects per KLOC), never to rank people. See cost estimation for function points as an alternative.

Fan-in and fan-out

  • Fan-in of a module is the number of modules that call it.
  • Fan-out is the number of modules it calls.

High fan-in means many things depend on a module, so changing it is risky but the module is well reused. High fan-out means the module depends on many others: it is probably doing too much and is fragile. A very high fan-out often marks a "god" module.

JS Fan-in and fan-out

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Depth of conditional nesting

This metric counts how deeply if, loops and switch statements are nested. Deep nesting is hard to read, hard to test (the number of paths multiplies) and a classic sign that a function should be split or use early returns.

JS Nesting depth

Press Run (or Ctrl + Enter) to see the console output here.

No output.

A common guideline is to keep nesting at three levels or fewer.

Cyclomatic complexity

Cyclomatic complexity counts independent paths through a function: one plus the number of decision points (if, case, loops, &&, ||, ?:). A value above about 10 usually means the function should be simplified. It is also the minimum number of tests needed for branch coverage of that function. See test design techniques.

Fog index (readability of documentation)

The Gunning fog index estimates the years of schooling a reader needs to understand a text on first reading:

TEXT
fog = 0.4 * ( words / sentences  +  100 * complexWords / words )

A complex word has three or more syllables. Documentation, requirements and user guides should aim for a fog index around 8 to 12. A score of 18 means the text is dense for almost everyone.

JS Fog index

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Process metrics

Process metrics measure how the team works, over time. They guide process improvement.

  • Defect density: defects divided by size (per KLOC or per function point).
  • Defect removal efficiency (DRE): the share of defects found before release.
  • Lead time and cycle time: from request to delivery, and from start of work to done.
  • Deployment frequency and change failure rate: how often you ship and how often a change causes an incident.
  • Review coverage and rework effort.
JS Defect density and DRE

Press Run (or Ctrl + Enter) to see the console output here.

No output.

People and project metrics

These describe the team and the project: effort per task, schedule variance, productivity trends, and people metrics such as attrition (share of staff leaving per year), absenteeism, total cost of the workforce and the employee Net Promoter Score (eNPS), which asks "how likely are you to recommend working here?" on a 0 to 10 scale. eNPS equals the percentage of promoters (9 to 10) minus the percentage of detractors (0 to 6).

JS Employee NPS

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Advantages and risks of measurement

Metrics make progress visible, support estimates, expose problem areas early, allow objective comparison between releases and justify improvement work. The risks are real too: collecting costs time; the wrong metric rewards the wrong behavior (Goodhart's law: when a measure becomes a target, it stops being a good measure); numbers get misread without context; and measuring individuals harms trust. Prefer a few metrics tied to a goal, look at trends rather than single values, and use them to ask questions, not to punish.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A module is called by 12 other modules and calls 2. What are its fan-in and fan-out?

    Fan-in counts callers, fan-out counts callees.
  2. 2. Which is a dynamic product metric?

    Dynamic metrics are measured while the software runs. The others are computed statically.
  3. 3. 190 defects were found before release and 10 after. What is the defect removal efficiency?

    DRE = 190 / (190 + 10) = 95%.
  4. 4. What does Goodhart's law warn about?

    People optimize the number instead of the goal, so use metrics to inform, not as quotas.

Summary

  • Measures, metrics and indicators turn attributes of software, process and people into numbers.
  • Product metrics: size, fan-in/fan-out, nesting depth, cyclomatic complexity, fog index (static) and response time or MTBF (dynamic).
  • Process metrics: defect density, DRE, lead time, deployment frequency.
  • People metrics: attrition, absenteeism, workforce cost, eNPS.
  • Use few metrics, watch trends, and never turn a metric into a quota.

Next: Coding standards and documentation.