Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Code Metrics For Improving Design

Code Metrics For Improving Design

Using code metrics, we can find problems in our software that make it hard for our design to change. This presentation shows an example of using complexity metrics to find a trouble spot, and a few first steps in the refactoring process.

Avatar for Christopher Styles

Christopher Styles

October 31, 2013

Other Decks in Technology

Transcript

  1. SOLID Single responsibility, dependency inversion... DRY Don’t repeat yourself Law

    of Demeter Loose coupling, avoid train wrecks TRUE Transparent, reasonable, usable, exemplary
  2. SOLID Single responsibility, dependency inversion... DRY Don’t repeat yourself Law

    of Demeter Loose coupling, avoid train wrecks TRUE Transparent, reasonable, usable, exemplary
  3. SOLID Single responsibility, dependency inversion... DRY Don’t repeat yourself Law

    of Demeter Loose coupling, avoid train wrecks TRUE Transparent, reasonable, usable, exemplary “Alexander, I think the Law of Demeter is shit and never follow it.” --DHH
  4. Tight coupling = makes our design hard to change Duplication

    = makes our design hard to change Complex methods = make our design hard to change
  5. Tight coupling = makes our design hard to change Duplication

    = makes our design hard to change Complex methods = make our design hard to change …etc = makes our design hard to change
  6. Score of Means 0-10 Awesome 11-20 Good enough 21-40 Might

    need refactoring 41-60 Possible to justify 61-100 Danger 100-200 Whoop, whoop, whoop 200 + Someone please think of the children — Jake Skruggs, author of metric_fu http://jakescruggs.blogspot.com/2008/08/whats-good- og-score.html
  7. Score of Means 0-10 Awesome 11-20 Good enough 21-40 Might

    need refactoring 41-60 Possible to justify 61-100 Danger 100-200 Whoop, whoop, whoop 200 + Someone please think of the children — Jake Skruggs, author of metric_fu http://jakescruggs.blogspot.com/2008/08/whats-good- og-score.html poor metrics = makes our design hard to change
  8. Attribute Class Variable Boolean Parameter Control Parameter Data Clump Duplicate

    Method Call Feature Envy Utility Function Irresponsible Module Long Parameter List Long Yield List Nested Iterators Simulated Polymorphism Nil Check Repeated Conditional Too Many Instance Variables Too Many Methods Too Many Statements Uncommunicative Name Unused Parameters
  9. Metrics can help you... Identify problems Reveal Interactions Measure pain

    Discover code smells Expose poor design Expose di culty: In changing objects In testing, In understanding In reusing
  10. Flog ABC metric with a ruby bias against metaprogramming… Reek

    Detect code smells. Flay Analyzes code for structural similarities (duplication). Rails Best Practices Checks the quality of your Rails code. Brakeman A static analysis security vulnerability scanner. Cane Fails your build if code quality thresholds are not met. Simplecov Test coverage analysis.