HEX: Change Risk as Hazard × Exposure
Abstract
Two families of software metric have grown up without meeting. One measures how dangerous a piece of code is from its structure - cyclomatic complexity, coupling, the Chidamber–Kemerer suite, the Maintainability Index. The other measures how well a change would be caught, from its tests - statement and branch coverage, mutation score, combinatorial coverage of the input space. Very few metrics draw on both, and the best-known that does - CRAP - multiplies complexity by uncovered code and stops there, inheriting a proxy for test quality that has been known for a decade to be weak. HEX is a per-construct change-risk score that spans the gap: risk is hazard, how much a change can break, times exposure, how little the tests would notice. Hazard combines complexity and efferent coupling; exposure combines coverage and the variety of inputs the tests actually drive and assert on. The CRAP-lineage variant of the same components reduces to CRAP exactly, so HEX contains it rather than competing with it. The asserted-variety signal that separates HEX from its coverage-based ancestors is only cheaply computable because the EK9 language makes @Test and assert first-class constructs rather than library conventions: the compiler owns the assertion grammar, so which construct's result a test pins down is a by-product of parsing, not an inference over a test framework. HEX is, in that sense, less a new formula than a demonstration of what pulling test structure into the language makes available. This is a position paper: the metric is argued, not validated. The paper is explicit about the calibration bind that makes it so - a corpus with a defect history lacks the input-variety signal, and a language new enough to emit the signal lacks a defect history — and about the ablation on a defect-labelled corpus that would settle whether asserted input variety adds predictive power over coverage.
// Source
Authors: Stephen Limb