development by the numbers we are going to measure
play

Development By The Numbers We Are Going To Measure Complexity Why - PowerPoint PPT Presentation

Development By The Numbers We Are Going To Measure Complexity Why Should We Care About Complexity? "The Central Enemy Of Reliability is Complexity" - Geer et al. Complexity And Quality Are Strongly Related Basic Metrics


  1. Development By The Numbers

  2. We Are Going To Measure Complexity

  3. Why Should We Care About Complexity?

  4. "The Central Enemy Of Reliability is Complexity" - Geer et al.

  5. Complexity And Quality Are Strongly Related

  6. Basic Metrics

  7. Cyclomatic Complexity

  8. Cyclomatic Complexity Number Of "Decision Points" In A Routine

  9. function foo ($a, $b) { $c = 0; if ($a) { $c = $a; } elseif ($b) { $c = $b; } if ($a && $b) { $c = $a + $b; } return $c; }

  10. function foo ($a, $b) { $c = 0; if ($a) { $c = $a; } elseif ($b) { $c = $b; } if ($a && $b) { $c = $a + $b; } return $c; }

  11. 4 function foo ($a, $b) { $c = 0; if ($a) { $c = $a; } elseif ($b) { $c = $b; } if ($a && $b) { $c = $a + $b; } return $c; }

  12. Simple Right?

  13. Cyclomatic Complexity (Single Method) 1 - 4 : Low Complexity 5 - 7 : Moderate Complexity 8 - 10 : High Complexity 11+ : Very High Complexity

  14. Cyclomatic Complexity (Average Per Method) 1 - 2 : Low Complexity 2 - 4 : Moderate Complexity 4 - 6 : High Complexity 6+ : Very High Complexity

  15. Compare: Average CC per Method Wordpress: 6.28 Drupal 7: 3.02 Drupal 8: 2.10 Symfony 2: 1.81 Zend Framework 2: 2.62 Laravel: 1.79

  16. Cyclomatic Complexity (Average Per Line Of Code) .01 - .05 : Low Complexity .05 - .10 : Moderate Complexity .10 - .15 : High Complexity .15+ : Very High Complexity

  17. Compare: Average CC per LOC Wordpress: 0.20 Drupal 7: 0.04 Drupal 8: 0.07 Symfony 2: 0.06 Zend Framework 2: 0.10 Laravel: 0.07

  18. N-Path Complexity

  19. N-Path Complexity Number Of "Unique Paths" In A Routine

  20. function foo ($a, $b) { $c = 0; if ($a) { $c = $a; } elseif ($b) { $c = $b; } if ($a && $b) { $c = $a + $b; } return $c; }

  21. function foo ($a, $b) { $c = 0; if ($a) { $c = $a; } elseif ($b) { $c = $b; } if ($a && $b) { $c = $a + $b; } return $c; }

  22. function foo ($a, $b) { $c = 0; if ($a) { $c = $a; } elseif ($b) { $c = $b; } if ($a && $b) { $c = $a + $b; } return $c; }

  23. function foo ($a, $b) { $c = 0; if ($a) { $c = $a; } elseif ($b) { $c = $b; } if ($a && $b) { $c = $a + $b; } return $c; }

  24. function foo ($a, $b) { $c = 0; if ($a) { $c = $a; } elseif ($b) { $c = $b; } if ($a && $b) { $c = $a + $b; } return $c; }

  25. 4 function foo ($a, $b) { $c = 0; if ($a) { $c = $a; } elseif ($b) { $c = $b; } if ($a && $b) { $c = $a + $b; } return $c; }

  26. They Are The Same?

  27. Not Generally!

  28. function foo2 ($a, $b, $c) { $d = 0; CC: if ($a) { $d += $a; NPath: } if ($b) { $d += $b; } if ($c) { $d += $c; } return $d; }

  29. function foo2 ($a, $b, $c) { $d = 0; CC: if ($a) { $d += $a; NPath: } if ($b) { $d += $b; } if ($c) { $d += $c; } return $d; }

  30. function foo2 ($a, $b, $c) { $d = 0; CC: 4 if ($a) { $d += $a; NPath: } if ($b) { $d += $b; } if ($c) { $d += $c; } return $d; }

  31. function foo2 ($a, $b, $c) { $d = 0; CC: 4 if ($a) { $d += $a; NPath: } if ($b) { $d += $b; } if ($c) { $d += $c; } return $d; }

  32. function foo2 ($a, $b, $c) { $d = 0; CC: 4 if ($a) { $d += $a; NPath: } if ($b) { $d += $b; } if ($c) { $d += $c; } return $d; }

  33. function foo2 ($a, $b, $c) { $d = 0; CC: 4 if ($a) { $d += $a; NPath: } if ($b) { $d += $b; } if ($c) { $d += $c; } return $d; }

  34. function foo2 ($a, $b, $c) { $d = 0; CC: 4 if ($a) { $d += $a; NPath: } if ($b) { $d += $b; } if ($c) { $d += $c; } return $d; }

  35. function foo2 ($a, $b, $c) { $d = 0; CC: 4 if ($a) { $d += $a; NPath: } if ($b) { $d += $b; } if ($c) { $d += $c; } return $d; }

  36. function foo2 ($a, $b, $c) { $d = 0; CC: 4 if ($a) { $d += $a; NPath: } if ($b) { $d += $b; } if ($c) { $d += $c; } return $d; }

  37. function foo2 ($a, $b, $c) { $d = 0; CC: 4 if ($a) { $d += $a; NPath: } if ($b) { $d += $b; } if ($c) { $d += $c; } return $d; }

  38. function foo2 ($a, $b, $c) { $d = 0; CC: 4 if ($a) { $d += $a; NPath: } if ($b) { $d += $b; } if ($c) { $d += $c; } return $d; }

  39. function foo2 ($a, $b, $c) { $d = 0; CC: 4 if ($a) { $d += $a; NPath: 8 } if ($b) { $d += $b; } if ($c) { $d += $c; } return $d; }

  40. function foo2 ($a, $b, $c) { $d = 0; CC: 4 if ($a) { $d += $a; NPath: 8 } if ($b) { 2^(CC-1) $d += $b; } if ($c) { $d += $c; } return $d; }

  41. N-Path Complexity <16 : Low Complexity 17-128 : Moderate Complexity 129-1024 : High Complexity 1025+ : Very High Complexity

  42. N-Path Complexity Minimum Number Of Tests Required To Completely Test A Routine

  43. N-Path Complexity entity_load() CC: N-Path:

  44. N-Path Complexity entity_load() CC: 2 N-Path:

  45. Cyclomatic Complexity 1 - 4 : Low Complexity 5 - 7 : Moderate Complexity 8 - 10 : High Complexity 11+ : Very High Complexity

  46. N-Path Complexity entity_load() CC: 2 N-Path: 2

  47. N-Path Complexity drupal_http_request() CC: N-Path:

  48. N-Path Complexity drupal_http_request() CC: 41 N-Path:

  49. Cyclomatic Complexity 1 - 4 : Low Complexity 5 - 7 : Moderate Complexity 8 - 10 : High Complexity 11+ : Very High Complexity

  50. N-Path Complexity drupal_http_request() CC: 41 N-Path: 25,303,344,960

  51. To Completely Test drupal_http_request() At 1 Line Of Code Per Test Would Require 2 Terabytes Worth Of Tests

  52. To Completely Test drupal_http_request() At 1 Line Of Code Per Test Would Require 412 DVD's Worth Of Tests

  53. To Completely Test drupal_http_request() At 1 Line Of Code Per Test Would Require 670k Drupals Worth Of Tests

  54. And That's Not The Worst One!

  55. N-Path Complexity _date_repeat_rrule_process() CC: N-Path:

  56. N-Path Complexity _date_repeat_rrule_process() CC: 81 N-Path:

  57. N-Path Complexity _date_repeat_rrule_process() CC: 81 N-Path: 19,781,719,256

  58. N-Path Complexity _date_repeat_rrule_process() CC: 81 N-Path: 19,781,719,256 ,250,000,000,000

  59. N-Path Complexity _date_repeat_rrule_process() CC: 81 N-Path: 19,781,719,256 ,250,000,000,000 ,000,000,000

  60. To Completely Test _date_repeat_rrule_process() At 1 Line Of Code Per Test Would Require 336T 2009's Worth Of Tests

  61. To Completely Test _date_repeat_rrule_process() At 1 Line Of Code Per Test Would Require 1 Greenland Ice Cap of microSD cards Worth Of Tests

  62. CRAP

  63. CRAP (Change Risk Analysis Predictions)

  64. CC = Cyclomatic Complexity (method) COV = Test Coverage (percent) CRAP = CC + (CC^2 * (1 - COV)^3)

  65. CRAP Relates Complexity And Test Coverage

  66. CRAP Increasing Test Coverage Lowers CRAP Decreasing Complexity Lowers CRAP

  67. CRAP A Low Complexity Method With No Tests Is Good

  68. CRAP A Low Complexity Method With Good Tests Is Great

  69. CRAP A Moderate Complexity Method With Good Tests Is OK

  70. CRAP A Moderate Complexity Method With No Tests Is CRAP

  71. CRAP < 5 : GREAT Code 5 - 15 : Acceptable Code 15-30 : Eih... Code 30+ : CRAPpy Code

  72. How Do We Apply These Metrics?

  73. Sebastian Bergmann PHPUnit DbUnit www.phpqatools.org PHPLOC www.jenkins-php.org PHPCPD PHPCOV hphpa

  74. PHPLOC

  75. PHPLOC By Sebastian Bergmann

  76. PHPLOC By Sebastian Bergmann Command Line Tool

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend