Google's 'CRAP' Metric Exposes the Real Cost of Bad Code

Code Is Crap

Google engineer Alberto Savoia introduces CRAP, a code quality metric that combines cyclomatic complexity and test coverage to flag risky code. The formula: CRAP = complexity^2 * (1 - coverage/100)^3 + complexity. High CRAP scores indicate code that's both complex and poorly tested—a recipe for bugs and maintenance nightmares. The post explains how to calculate CRAP, interpret scores, and use tools like Crap4J to identify and refactor problematic code.

The CRAP metric is a simple and effective way to identify code that is both complex and poorly tested, and therefore likely to be buggy and expensive to maintain.

More from this day

2026-09-16