Hasty Briefsbeta

Bilingual

Code Is Crap

2 hours ago
  • CRAP stands for Change Risk Anti-Patterns, a memorable acronym for identifying poor-quality code.
  • The metric was created in 2007 by Alberto Savoia and Bob Evans, inspired by developers' subjective complaints about 'crappy' code.
  • CRAP1 formula: CRAP1(m) = comp(m)^2 * (1 - cov(m)/100)^3 + comp(m), where comp is cyclomatic complexity and cov is code coverage; scores above 30 indicate 'crappy' methods.
  • The formula was developed empirically using open source and commercial Java projects with JUnit tests, iterating to match subjective evaluations.
  • High complexity with low test coverage signals poor testability and design, as developers often avoid writing tests for convoluted code.
  • CRAP1 has limitations: it doesn't account for higher-order metrics like cohesion or coupling, and high coverage can still have weak tests.
  • CRAP has been ported to multiple languages and platforms (e.g., .NET, PHP, Ruby) and is used in tools like Clover and Cobertura.
  • Despite initial inactivity, the metric gained traction; users can implement CRAP via existing tools or search for language-specific ports.
  • Challenges include broken download links and incompatible versions; a workaround exists for Java 7 compatibility.
  • The post calls for further development and invites contributions, especially for unported languages like COBOL.