Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Important metrics for Measuring Code Health

189 views

Published on

Slides for the talk that I gave at #AgileIndy2018.

Abstract:
There are a bunch of different ways to measure code quality. What are the most important ones for your team to focus on? No matter what language(s) your team is working with or your role on the team, you’ll walk away from this talk with a clear guide of what to pay attention to.

Published in: Software

Important metrics for Measuring Code Health

  1. 1. IMPORTANT METRICS @mscottford BY M. SCOTT FORD
 CO-FOUNDER & CHIEF CODE WHISPERER, CORGIBYTES FOR MEASURING CODE HEALTH
  2. 2. @mscottford
  3. 3. @mscottford METRICS YOUR DOCTOR USES
  4. 4. @mscottford AGE? METRICS YOUR DOCTOR USES
  5. 5. @mscottford AGE? WEIGHT? METRICS YOUR DOCTOR USES
  6. 6. @mscottford AGE? WEIGHT? HEIGHT? METRICS YOUR DOCTOR USES
  7. 7. @mscottford AGE? WEIGHT? HEIGHT? METRICS YOUR DOCTOR USES TEMPERATURE?
  8. 8. @mscottford AGE? WEIGHT? HEIGHT? BLOOD O2 LEVEL? METRICS YOUR DOCTOR USES TEMPERATURE?
  9. 9. @mscottford AGE? WEIGHT? HEIGHT? BLOOD O2 LEVEL? METRICS YOUR DOCTOR USES TEMPERATURE? BLOOD PRESSURE?
  10. 10. @mscottford AGE? WEIGHT? HEIGHT? BLOOD O2 LEVEL? ALL OF THESE ARE USED TOGETHER TEMPERATURE? BLOOD PRESSURE?
  11. 11. @mscottford AGE? WEIGHT? HEIGHT? BLOOD O2 LEVEL? TOGETHER THEY PROVIDE SOME HINTS TEMPERATURE? BLOOD PRESSURE?
  12. 12. ABOUT ME @mscottford
  13. 13. @mscottford CHIEF CODE WHISPERER CO-FOUNDER AND
  14. 14. @mscottford WE PERFORM CODE INSPECTIONS
  15. 15. @mscottford WE’VE LOOKED AT A LOT OF PROJECTS
  16. 16. WHAT METRICS DO WE LOOK AT? @mscottford
  17. 17. @mscottford ??? ??? ???
  18. 18. @mscottford ??? ??? CHURN
  19. 19. @mscottford CHURN A measure of how many times file has changed over a specific amount of time
  20. 20. @mscottford LIFETIME CHURN A measure of how many times file has changed over the life of a project
  21. 21. @mscottford RECENT CHURN A measure of how many times file has changed during the last 3 months
  22. 22. @mscottford ??? ??? CHURN
  23. 23. @mscottford ??? CODE COVERAGE CHURN
  24. 24. @mscottford CODE COVERAGE A measure of how much of the application is executed when a test is performed
  25. 25. @mscottford ACCEPTANCE TEST CODE COVERAGE A measure of how much of the application is executed when the acceptance tests are run
  26. 26. @mscottford INTEGRATION TEST CODE COVERAGE A measure of how much of the application is executed when the integration tests are run
  27. 27. @mscottford UNIT TEST CODE COVERAGE A measure of how much of the application is executed when the unit tests are run
  28. 28. @mscottford ??? CODE COVERAGE CHURN
  29. 29. @mscottford COMPLEXITY CODE COVERAGE CHURN
  30. 30. @mscottford COMPLEXITY A measure of how difficult a chunk of code is to work with
  31. 31. @mscottford A measure of unique code paths for a block of code CYCLOMATIC COMPLEXITY
  32. 32. @mscottford A measure of the cognitive effort required to understand a block of code COGNITIVE COMPLEXITY
  33. 33. @mscottford HOW DO WE COLLECT THESE METRICS?
  34. 34. CHURN • git-churn script by Corey Haines & Gary Bernhardt • https://github.com/garybernhardt/dotfiles/blob/master/bin/git- churn @mscottford
  35. 35. CODE COVERAGE • Run tests with code coverage collection tool • These vary by language •Ruby: simplecov, rcov •Python: coverage.py • C#/.NET: dotCover, NCover, OpenCover •Java: Clover, JCov, JCoCo, OpenClover, Cobertura, •JavaScript: Istanbul, Jest @mscottford
  36. 36. COMPLEXITY • Run a static analysis tool to collect the data • These also vary by language • Ruby: rubocop, flog • Python: radon • C#/.NET: MS Visual Studio, NDepend, ReSharper, SonarQube • Java: PMD, GMetrics, IntelliJ, SonarQube, • JavaScript: ESLint, JSHint, ccmj @mscottford
  37. 37. WHY THESE METRICS? @mscottford
  38. 38. @mscottford CHURN Code that has changed in the past is more likely to change in the future. A good stand-in for single responsibility principle.
  39. 39. @mscottford CODE COVERAGE Code that is tested is safer to change.
  40. 40. @mscottford COMPLEXITY The more complex code is the more dangerous to change.
  41. 41. @mscottford WHAT ARE ‘GOOD’ METRIC VALUES?
  42. 42. @mscottford CHURN Low is better. High is not bad, but outliers are. Recent churn is more important than lifetime churn.
  43. 43. @mscottford CODE COVERAGE 100% across the entire codebase is asymptotic. 85% is a reasonable target. Unit > Integration > Acceptance
  44. 44. @mscottford COMPLEXITY Provides best info at method level: 1 - 5 : Good 6 - 10 : Complex > 10 : Extremely Complex
  45. 45. @mscottford USING THESE METRICS TOGETHER
  46. 46. @mscottford
  47. 47. @mscottford
  48. 48. LET’S EXPLORE COMMON SCENARIOS @mscottford
  49. 49. @mscottford COMPLEXITY CODE COVERAGE CHURN HEALTHY
  50. 50. @mscottford COMPLEXITY LOW CODE COVERAGE HIGH CHURN LOW HEALTHY
  51. 51. @mscottford COMPLEXITY CODE COVERAGE CHURN DESIGN SMELL
  52. 52. @mscottford COMPLEXITY LOW CODE COVERAGE HIGH CHURN HIGH DESIGN SMELL
  53. 53. @mscottford COMPLEXITY CODE COVERAGE CHURN TESTING NOT A FOCUS
  54. 54. @mscottford COMPLEXITY LOW CODE COVERAGE LOW CHURN LOW TESTING NOT A FOCUS
  55. 55. @mscottford COMPLEXITY CODE COVERAGE CHURN REFACTORING NOT A FOCUS
  56. 56. @mscottford COMPLEXITY HIGH CODE COVERAGE HIGH CHURN LOW REFACTORING NOT A FOCUS
  57. 57. @mscottford COMPLEXITY CODE COVERAGE CHURN UNHEALTHY: LOW PRIORITY
  58. 58. @mscottford COMPLEXITY HIGH CODE COVERAGE LOW CHURN LOW UNHEALTHY: LOW PRIORITY
  59. 59. @mscottford COMPLEXITY CODE COVERAGE CHURN UNHEALTHY: HIGH PRIORITY
  60. 60. @mscottford COMPLEXITY HIGH CODE COVERAGE LOW CHURN HIGH UNHEALTHY: HIGH PRIORITY
  61. 61. @mscottford QUESTIONS?
  62. 62. @mscottford CONTACT INFO @mscottford @corgibytes corgibytes.com LegacyCode.Rocks

×