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.

Magic behind the numbers - software metrics in practice

7,815 views

Published on

We use static code analysis tools more often these days that create great reports and funky graphs. But do we understand what it all mean?
Software metrics tends to be magic numbers for a lot of people, but they don't really have to be. Let me introduce you to a few basic and
most popular software metric and tools and explain you what they mean and how you can use them to produce better software.

Published in: Technology
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, eBooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Magic behind the numbers - software metrics in practice

  1. 1. Magic behind the numbers<br />Software metrics in practice<br />Sebastian Marek, Software Architect<br />
  2. 2. @proofek<br /><ul><li>a Pole living in Sheffield
  3. 3. over 10 years PHP experience
  4. 4. co-author of 2 PHP books
  5. 5. big fan of process automation
  6. 6. TDD and CI
  7. 7. occasionally contributes to open source projects
  8. 8. wants to be a knight</li></li></ul><li>Agenda<br />What I will be talking about<br /><ul><li>Code metrics
  9. 9. Design metrics</li></ul>What I will not be talking about<br /><ul><li>Project metrics</li></li></ul><li>Most effective code quality measure<br />
  10. 10.
  11. 11. “It is the mapping of a particular characteristic of a measured entity to a numerical value”<br />Source: Object-Oriented Metrics in Practice<br />What is a metric?<br />
  12. 12. “Good design quality metrics are not necessarily indicative of good designs. Likewise, bad design quality metrics are not necessarily indicative of bad designs”<br />Source: JdependDocs<br />Software design<br />
  13. 13. System maintenance <br /><ul><li>Obsolete documentation
  14. 14. Convoluted design
  15. 15. Intensive patch mechanism (hacking)
  16. 16. Large size
  17. 17. Severe duplication
  18. 18. Obsolete parts (dead code)
  19. 19. Long build times
  20. 20. Loss of original developers</li></li></ul><li>Simple metrics<br /><ul><li>CLOC – comment lines of code
  21. 21. ELOC – executable lines of code
  22. 22. LOC – lines of code
  23. 23. NCLOC – non comment lines of code
  24. 24. NOP – number of packages
  25. 25. NOC – number of classes
  26. 26. NOM – number of methods
  27. 27. CYCLO – cyclomatic complexity number</li></li></ul><li>phploc<br />phploc 1.6.1 by Sebastian Bergmann.<br />Directories: 6<br />Files: 20<br />Lines of Code (LOC): 5478<br />Cyclomatic Complexity / Lines of Code: 0.13<br />Comment Lines of Code (CLOC): 2143<br />Non-Comment Lines of Code (NCLOC): 3335<br />Namespaces: 0<br />Interfaces: 1<br />Classes: 18<br /> Abstract: 2 (11.11%)<br /> Concrete: 16 (88.89%)<br /> Average Class Length (NCLOC): 191<br />Methods: 151<br /> Scope:<br /> Non-Static: 143 (94.70%)<br /> Static: 8 (5.30%)<br /> Visibility:<br /> Public: 116 (76.82%)<br /> Non-Public: 35 (23.18%)<br /> Average Method Length (NCLOC): 22<br />Cyclomatic Complexity / Number of Methods: 3.72<br />Anonymous Functions: 0<br />Functions: 2<br />Constants: 4<br /> Global constants: 3<br /> Class constants: 1<br />
  28. 28. JAVA<br />Source: Object-Oriented Metrics in Practice (based on 45 Java projects)<br />
  29. 29. C++<br />Source: Object-Oriented Metrics in Practice (based on 37 C++ projects)<br />
  30. 30. WMC and AMW<br />Weighted Method Count – total complexity of a class<br />Average Method Weight – average complexity of a method<br />
  31. 31. JAVA<br />Source: Object-Oriented Metrics in Practice (based on 45 Java projects)<br />
  32. 32. C++<br />Source: Object-Oriented Metrics in Practice (based on 37 C++ projects)<br />
  33. 33. Coverage report<br />
  34. 34.
  35. 35. C.R.A.P<br />
  36. 36. C.R.A.P<br />Change<br />Risk<br />Analysis and <br />Predictions<br />Change Risk Analysis and Predictions<br />
  37. 37. C.R.A.P formula<br />Code coverage = 100%<br />Code coverage = 0%<br />
  38. 38. Cyclomatic Complexity<br />Cyclomatic complexity measures the amount of decision logic in a single software module.<br />
  39. 39. Cyclomatic Complexity Number (CCN)<br />Conditional statements:<br /><ul><li>?
  40. 40. case
  41. 41. elseif
  42. 42. for
  43. 43. foreach
  44. 44. if
  45. 45. while</li></li></ul><li>CCN2<br />Conditional statements:<br /><ul><li>?
  46. 46. case
  47. 47. elseif
  48. 48. for
  49. 49. foreach
  50. 50. if
  51. 51. while
  52. 52. &&
  53. 53. ||
  54. 54. or
  55. 55. and
  56. 56. xor</li></li></ul><li>Cyclomatic complexity<br />Conditional statements:<br /><ul><li>?
  57. 57. case
  58. 58. elseif
  59. 59. for
  60. 60. foreach
  61. 61. if
  62. 62. while
  63. 63. &&
  64. 64. ||
  65. 65. or
  66. 66. and
  67. 67. xor
  68. 68. catch</li></li></ul><li>Cyclomatic complexity - example<br />
  69. 69. Cyclomatic complexity - example<br />
  70. 70. Cyclomatic complexity - example<br />
  71. 71. Cyclomatic complexity - example<br />
  72. 72. Cyclomatic complexity - example<br />
  73. 73. Cyclomatic complexity - example<br />
  74. 74. Cyclomatic complexity - example<br />
  75. 75. Cyclomatic complexity - example<br />
  76. 76. NPATH – acyclic execution path complexity<br />NPATH is an objective measure of software complexity related to the ease with which software can be comprehensively tested<br />Edgar H. Sibley<br />
  77. 77. NPATH – acyclic execution path complexity<br />expressions Number of && and || operators in expression<br />if NP(<if-range>)+NP(<expr>)+1<br /> if-else NP(<if-range>)+NP(<else-range>)+NP(<expr>)<br />while NP(<while-range>)+NP(<expr>)+1<br />for NP(<for-range>)+NP(<expr1>)+NP(<expr2>)+<br /> NP(<expr3>)+1<br />break 1<br /> continue 1<br /> return 1<br /> sequential 1<br />function call 1<br />
  78. 78. NPATH – example<br />
  79. 79. NPATH – example<br />
  80. 80. NPATH – example<br />
  81. 81. NPATH – example<br />
  82. 82. NPATH – example<br />
  83. 83. NPATH – example<br />
  84. 84. NPATH – example<br />
  85. 85. NPATH – example<br />
  86. 86. NPATH – example<br />
  87. 87. NPATH – example<br />
  88. 88. NPATH – example<br />
  89. 89. NPATH – example<br />
  90. 90. NPATH – example<br />
  91. 91. NPATH – example<br />
  92. 92. NPATH – example<br />
  93. 93. NPATH – example<br />
  94. 94. NPATH – example<br />
  95. 95. NPATH – example<br />
  96. 96. NPATH – example<br />
  97. 97. PHP Depend<br />PHP_Depend 0.10.6 by Manuel Pichler<br />Parsing source files:<br />.................... 20<br />Executing CyclomaticComplexity-Analyzer:<br />............. 261<br />Executing ClassLevel-Analyzer:<br />............ 247<br />Executing CodeRank-Analyzer:<br />. 28<br />Executing Coupling-Analyzer:<br />............. 267<br />Executing Hierarchy-Analyzer:<br />............ 246<br />Executing Inheritance-Analyzer:<br />. 30<br />Executing NPathComplexity-Analyzer:<br />.............. 283<br />Executing NodeCount-Analyzer:<br />........ 174<br />Executing NodeLoc-Analyzer:<br />.......... 205<br />Generating pdepend log files, this may take a moment.<br />Time: 00:05; Memory: 25.50Mb<br />
  98. 98. PHP Mess Detector<br />
  99. 99. Overview pyramid<br />
  100. 100. Size and complexity – direct metrics<br />
  101. 101. Size and complexity – computed proportions<br />
  102. 102. System coupling – direct metrics<br />
  103. 103. System coupling – computed proportions<br />
  104. 104. System inheritance<br />
  105. 105. Complete Overview Pyramid<br />
  106. 106. PHP<br />http://pdepend.org/<br />
  107. 107. Metrics visualisation with Sonar<br />
  108. 108. Metrics visualisation with Sonar<br />
  109. 109. Violations reporting<br />
  110. 110. SIG Maintainability Model<br />--<br />-<br />0<br />+<br />++<br />Very bad<br />Bad<br />Average<br />Good<br />Very good<br />
  111. 111. Technical Debt<br />
  112. 112. Summary<br />“We believe that software metrics, in general, are just tools. No single metric can tell the whole story; it’s just one more data point. “<br />“Metrics are meant to be used by developers, not the other way around – the metric should work for you, you should not have to work for the metric. “<br />“Metrics should never be an end unto themselves. Metrics are meant to help you think, not to do the thinking for you.”<br />Alberto Savoia<br />
  113. 113. Resources<br /><ul><li>PHP Depend - http://pdepend.org/
  114. 114. PHP Mess Detector - http://phpmd.org/
  115. 115. Manuel’s home page - http://manuel-pichler.de/
  116. 116. PHPUnit - http://www.phpunit.de/
  117. 117. phploc- http://sebastianbergmann.github.com/phploc/
  118. 118. Sonar - http://www.sonarsource.org/
  119. 119. “Object-Oriented Metrics in Practice” by Michele Lanzaand RaduMarinescu (ISBN 978-3540244295)</li></li></ul><li>Questions<br />Questions?<br /> http://joind.in/3588<br />

×