The Dark Side of Code Metrics
Why do we care so much?• Trying to qualify work completed• Trying to predict future work
Lines of Code (LoC)• Quantifying outstanding or completed  work• What is better, having fewer or more  lines of code?
Lines of Code (LoC)
Lines of Code (LoC)
Lines of Code (LoC)
Lines of Code (LoC)• 1000s of ways to write the same thing• Context is king• An estimating crutch for management
Amount of Comments• Sometimes seen as LoC:LoComments ratio• Driven by the belief that comments  increase the understandabi...
Comments
Comments
Comments
Comments
Comments
Amount of Comments•   A crutch for lazy coding•   Misuse of existing systems•   Creates a maintenance burden•   Guaranteed...
Code Coverage• Executing code via automated tests  increases the quality of the code• %age of lines of code executed by  a...
Code Coverage1. Codebase has 85% coverage2. Developer refactors some code and   commits changes3. Codebase has 82% coverag...
Code Coverage• Codebase has 100% coverage• Developer makes daily releases to fix  daily defect reports          What’s the...
Code Coverage• Class has 40 lines of code and 0%  coverage          What’s the problem?
Code Coverage• Class has 5 lines of code and 0%  coverage
Code Coverage• Context is king• Who decides the arbitrary “acceptable”  %age?• Who decides what code needs to be  tested?
Maintainability Index= MAX(0,(171 - 5.2 * log(Halstead Volume) - 0.23 * (Cyclomatic Complexity) - 16.2 * log(Lines of Code...
Maintainability Index• What does it tell us though?• Comparison of two codebases?  – Only if they have very similar LoC an...
Maintainability Index• With no peer comparison it is an arbitrary  number• What is an application’s peer though?
Generated Code• Should metrics be applied?• What does the metric mean?• How easily can you exclude/separate?
The Lie• Metrics offer emperical evidence about a  codebase• By themselves, metrics provide meaning
The Truth• Metrics are nothing more than statistics• Can be made to represent anything• The numbers, by themselves, repres...
The Light Side• The output numbers mean nothing by  themselves• Look at interesting comparisons  – Time based  – Module ba...
Deltas Over Time• How did <metric> change  – since last run?  – since last release?
Related Metrics• Code Coverage vs Defect Reports• Defect Reports vs Code Churn• Look at the deltas over a time period
Creating valuable meaning   requires hard work
@dbelchamdonald.belcham@igloocoder.com
Upcoming SlideShare
Loading in …5
×

The Dark Side of Code Metrics

727
-1

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
727
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Heavy comments
  • Content revealing code
  • Out of sync
  • The Dark Side of Code Metrics

    1. 1. The Dark Side of Code Metrics
    2. 2. Why do we care so much?• Trying to qualify work completed• Trying to predict future work
    3. 3. Lines of Code (LoC)• Quantifying outstanding or completed work• What is better, having fewer or more lines of code?
    4. 4. Lines of Code (LoC)
    5. 5. Lines of Code (LoC)
    6. 6. Lines of Code (LoC)
    7. 7. Lines of Code (LoC)• 1000s of ways to write the same thing• Context is king• An estimating crutch for management
    8. 8. Amount of Comments• Sometimes seen as LoC:LoComments ratio• Driven by the belief that comments increase the understandability of code
    9. 9. Comments
    10. 10. Comments
    11. 11. Comments
    12. 12. Comments
    13. 13. Comments
    14. 14. Amount of Comments• A crutch for lazy coding• Misuse of existing systems• Creates a maintenance burden• Guaranteed to be incorrect
    15. 15. Code Coverage• Executing code via automated tests increases the quality of the code• %age of lines of code executed by automated tests
    16. 16. Code Coverage1. Codebase has 85% coverage2. Developer refactors some code and commits changes3. Codebase has 82% coverage, build fails because threshold is 85% What went wrong?
    17. 17. Code Coverage• Codebase has 100% coverage• Developer makes daily releases to fix daily defect reports What’s the problem?
    18. 18. Code Coverage• Class has 40 lines of code and 0% coverage What’s the problem?
    19. 19. Code Coverage• Class has 5 lines of code and 0% coverage
    20. 20. Code Coverage• Context is king• Who decides the arbitrary “acceptable” %age?• Who decides what code needs to be tested?
    21. 21. Maintainability Index= MAX(0,(171 - 5.2 * log(Halstead Volume) - 0.23 * (Cyclomatic Complexity) - 16.2 * log(Lines of Code))*100 / 171)• Higher number means more maintainable
    22. 22. Maintainability Index• What does it tell us though?• Comparison of two codebases? – Only if they have very similar LoC and CC values• Comparison of two modules?• How hard it is to understand the code?
    23. 23. Maintainability Index• With no peer comparison it is an arbitrary number• What is an application’s peer though?
    24. 24. Generated Code• Should metrics be applied?• What does the metric mean?• How easily can you exclude/separate?
    25. 25. The Lie• Metrics offer emperical evidence about a codebase• By themselves, metrics provide meaning
    26. 26. The Truth• Metrics are nothing more than statistics• Can be made to represent anything• The numbers, by themselves, represent nothing• Interpretation is in the eye of the beholder
    27. 27. The Light Side• The output numbers mean nothing by themselves• Look at interesting comparisons – Time based – Module based – Developer based• Look for deltas rather than actuals
    28. 28. Deltas Over Time• How did <metric> change – since last run? – since last release?
    29. 29. Related Metrics• Code Coverage vs Defect Reports• Defect Reports vs Code Churn• Look at the deltas over a time period
    30. 30. Creating valuable meaning requires hard work
    31. 31. @dbelchamdonald.belcham@igloocoder.com

    ×