hn.today

Code Is Crap

testing.googleblog.com66 points44 comments
Screenshot of Code Is Crap

Change Risk Anti-Patterns (CRAP) is a metric suite coined to flag maintainability and testing risk in code by combining cyclomatic complexity and test coverage into a single score. The original CRAP1 formula computes a method score as comp(m)^2 * (1 - cov(m)/100)^3 + comp(m) and marks methods above 30 as "CRAPpy." The formula was derived empirically by fitting to many Java projects and their tests and validated against developers’ subjective judgments. The rationale is practical: highly complex methods that lack automated tests are harder to change safely, while good coverage usually signals testability and thoughtfulness in design. CRAP1 became popular, especially in agile circles, and was ported into multiple languages and tools (Cobertura, Clover, Crap4J and variants).

CRAP1 is explicitly pragmatic rather than complete: it can be gamed by superficial tests, some complexity is unavoidable, and the metric does not yet include higher-level design measures like cohesion or coupling. Adoption spawned numerous ports and integrations across ecosystems, though some plugins aged poorly and required maintenance (notably Java 7 incompatibilities). Further work is planned to expand CRAP beyond this single anti-pattern, with guidance intended to help teams identify, reduce, and resist low-quality code.

Read on testing.googleblog.com44 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.