Upcoming SlideShare
Loading in …5
×

# Development by the numbers

8,117 views
8,054 views

Published on

Presentation from DrupalCon Portland: http://portland2013.drupal.org/node/1078

Published in: Technology
0 Comments
17 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

No Downloads
Views
Total views
8,117
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
44
Comments
0
Likes
17
Embeds 0
No embeds

No notes for slide

### Development by the numbers

1. 1. DevelopmentBy The Numbers
2. 2. We Are Going ToMeasure Complexity
3. 3. Why Should We CareAbout Complexity?
4. 4. - Geer et al."The Central Enemy OfReliability is Complexity"
5. 5. Complexity AndQuality Are StronglyRelated
6. 6. Basic Metrics
7. 7. CyclomaticComplexity
8. 8. Cyclomatic ComplexityNumber Of"Decision Points"In A Routine
9. 9. function foo(\$a, \$b) {\$c = 0;if (\$a) {\$c = \$a;} elseif (\$b) {\$c = \$b;}if (\$a && \$b) {\$c = \$a + \$b;}return \$c;}
10. 10. function foo(\$a, \$b) {\$c = 0;if (\$a) {\$c = \$a;} elseif (\$b) {\$c = \$b;}if (\$a && \$b) {\$c = \$a + \$b;}return \$c;}
11. 11. function foo(\$a, \$b) {\$c = 0;if (\$a) {\$c = \$a;} elseif (\$b) {\$c = \$b;}if (\$a && \$b) {\$c = \$a + \$b;}return \$c;}4
12. 12. SimpleRight?
13. 13. Cyclomatic Complexity(Single Method)1 - 4: Low Complexity5 - 7: Moderate Complexity8 - 10: High Complexity11+: Very High Complexity
14. 14. Cyclomatic Complexity(Average Per Method)1 - 2: Low Complexity2 - 4: Moderate Complexity4 - 6: High Complexity6+: Very High Complexity
15. 15. Compare:Average CC per MethodWordpress: 6.28Drupal 7: 3.02Drupal 8: 2.10Symfony 2: 1.81Zend Framework 2: 2.62Laravel: 1.79
16. 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. 17. Compare:Average CC per LOCWordpress: 0.20Drupal 7: 0.04Drupal 8: 0.07Symfony 2: 0.06Zend Framework 2: 0.10Laravel: 0.07
18. 18. N-PathComplexity
19. 19. N-Path ComplexityNumber Of"Unique Paths"In A Routine
20. 20. function foo(\$a, \$b) {\$c = 0;if (\$a) {\$c = \$a;} elseif (\$b) {\$c = \$b;}if (\$a && \$b) {\$c = \$a + \$b;}return \$c;}
21. 21. function foo(\$a, \$b) {\$c = 0;if (\$a) {\$c = \$a;} elseif (\$b) {\$c = \$b;}if (\$a && \$b) {\$c = \$a + \$b;}return \$c;}
22. 22. function foo(\$a, \$b) {\$c = 0;if (\$a) {\$c = \$a;} elseif (\$b) {\$c = \$b;}if (\$a && \$b) {\$c = \$a + \$b;}return \$c;}
23. 23. function foo(\$a, \$b) {\$c = 0;if (\$a) {\$c = \$a;} elseif (\$b) {\$c = \$b;}if (\$a && \$b) {\$c = \$a + \$b;}return \$c;}
24. 24. function foo(\$a, \$b) {\$c = 0;if (\$a) {\$c = \$a;} elseif (\$b) {\$c = \$b;}if (\$a && \$b) {\$c = \$a + \$b;}return \$c;}
25. 25. function foo(\$a, \$b) {\$c = 0;if (\$a) {\$c = \$a;} elseif (\$b) {\$c = \$b;}if (\$a && \$b) {\$c = \$a + \$b;}return \$c;}4
26. 26. They AreThe Same?
27. 27. NotGenerally!
28. 28. function foo2(\$a, \$b, \$c) {\$d = 0;if (\$a) {\$d += \$a;}if (\$b) {\$d += \$b;}if (\$c) {\$d += \$c;}return \$d;}CC:NPath:
29. 29. function foo2(\$a, \$b, \$c) {\$d = 0;if (\$a) {\$d += \$a;}if (\$b) {\$d += \$b;}if (\$c) {\$d += \$c;}return \$d;}CC:NPath:
30. 30. function foo2(\$a, \$b, \$c) {\$d = 0;if (\$a) {\$d += \$a;}if (\$b) {\$d += \$b;}if (\$c) {\$d += \$c;}return \$d;}CC: 4NPath:
31. 31. function foo2(\$a, \$b, \$c) {\$d = 0;if (\$a) {\$d += \$a;}if (\$b) {\$d += \$b;}if (\$c) {\$d += \$c;}return \$d;}CC: 4NPath:
32. 32. function foo2(\$a, \$b, \$c) {\$d = 0;if (\$a) {\$d += \$a;}if (\$b) {\$d += \$b;}if (\$c) {\$d += \$c;}return \$d;}CC: 4NPath:
33. 33. function foo2(\$a, \$b, \$c) {\$d = 0;if (\$a) {\$d += \$a;}if (\$b) {\$d += \$b;}if (\$c) {\$d += \$c;}return \$d;}CC: 4NPath:
34. 34. function foo2(\$a, \$b, \$c) {\$d = 0;if (\$a) {\$d += \$a;}if (\$b) {\$d += \$b;}if (\$c) {\$d += \$c;}return \$d;}CC: 4NPath:
35. 35. function foo2(\$a, \$b, \$c) {\$d = 0;if (\$a) {\$d += \$a;}if (\$b) {\$d += \$b;}if (\$c) {\$d += \$c;}return \$d;}CC: 4NPath:
36. 36. function foo2(\$a, \$b, \$c) {\$d = 0;if (\$a) {\$d += \$a;}if (\$b) {\$d += \$b;}if (\$c) {\$d += \$c;}return \$d;}CC: 4NPath:
37. 37. function foo2(\$a, \$b, \$c) {\$d = 0;if (\$a) {\$d += \$a;}if (\$b) {\$d += \$b;}if (\$c) {\$d += \$c;}return \$d;}CC: 4NPath:
38. 38. function foo2(\$a, \$b, \$c) {\$d = 0;if (\$a) {\$d += \$a;}if (\$b) {\$d += \$b;}if (\$c) {\$d += \$c;}return \$d;}CC: 4NPath:
39. 39. function foo2(\$a, \$b, \$c) {\$d = 0;if (\$a) {\$d += \$a;}if (\$b) {\$d += \$b;}if (\$c) {\$d += \$c;}return \$d;}CC: 4NPath: 8
40. 40. function foo2(\$a, \$b, \$c) {\$d = 0;if (\$a) {\$d += \$a;}if (\$b) {\$d += \$b;}if (\$c) {\$d += \$c;}return \$d;}CC: 4NPath: 82^(CC-1)
41. 41. N-Path Complexity<16: Low Complexity17-128: Moderate Complexity129-1024: High Complexity1025+: Very High Complexity
42. 42. N-Path ComplexityMinimum Number OfTests Required ToCompletely TestA Routine
43. 43. N-Path Complexityentity_load()CC:N-Path:
44. 44. N-Path Complexityentity_load()CC: 2N-Path:
45. 45. Cyclomatic Complexity1 - 4: Low Complexity5 - 7: Moderate Complexity8 - 10: High Complexity11+: Very High Complexity
46. 46. N-Path Complexityentity_load()CC: 2N-Path: 2
47. 47. N-Path Complexitydrupal_http_request()CC:N-Path:
48. 48. N-Path Complexitydrupal_http_request()CC: 41N-Path:
49. 49. Cyclomatic Complexity1 - 4: Low Complexity5 - 7: Moderate Complexity8 - 10: High Complexity11+: Very High Complexity
50. 50. N-Path Complexitydrupal_http_request()CC: 41N-Path: 25,303,344,960
51. 51. To Completely Testdrupal_http_request()At 1 Line Of Code Per TestWould Require2 TerabytesWorth Of Tests
52. 52. To Completely Testdrupal_http_request()At 1 Line Of Code Per TestWould Require412 DVDsWorth Of Tests
53. 53. To Completely Testdrupal_http_request()At 1 Line Of Code Per TestWould Require670k DrupalsWorth Of Tests
54. 54. And Thats NotThe Worst One!
55. 55. N-Path Complexity_date_repeat_rrule_process()CC:N-Path:
56. 56. N-Path Complexity_date_repeat_rrule_process()CC: 81N-Path:
57. 57. N-Path Complexity_date_repeat_rrule_process()CC: 81N-Path: 19,781,719,256
58. 58. N-Path Complexity_date_repeat_rrule_process()CC: 81N-Path: 19,781,719,256,250,000,000,000
59. 59. N-Path Complexity_date_repeat_rrule_process()CC: 81N-Path: 19,781,719,256,250,000,000,000,000,000,000
60. 60. To Completely Test_date_repeat_rrule_process()At 1 Line Of Code Per TestWould Require336T 2009sWorth Of Tests
61. 61. To Completely Test_date_repeat_rrule_process()At 1 Line Of Code Per TestWould Require1 Greenland Ice Cap ofmicroSD cardsWorth Of Tests
62. 62. CRAP
63. 63. CRAP(Change Risk Analysis Predictions)
64. 64. CC = Cyclomatic Complexity (method)COV = Test Coverage (percent)CRAP = CC + (CC^2 * (1 - COV)^3)
65. 65. CRAPRelates ComplexityAnd Test Coverage
66. 66. CRAPIncreasing Test Coverage Lowers CRAPDecreasing Complexity Lowers CRAP
67. 67. CRAPA Low Complexity MethodWith No TestsIs Good
68. 68. CRAPA Low Complexity MethodWith Good TestsIs Great
69. 69. CRAPA Moderate Complexity MethodWith Good TestsIs OK
70. 70. CRAPA Moderate Complexity MethodWith No TestsIs CRAP
71. 71. CRAP< 5: GREAT Code5 - 15: Acceptable Code15-30: Eih... Code30+: CRAPpy Code
72. 72. How Do WeApply TheseMetrics?
73. 73. Sebastian BergmannPHPUnitDbUnitPHPLOCPHPCPDPHPCOVhphpawww.phpqatools.orgwww.jenkins-php.org
74. 74. PHPLOC
75. 75. PHPLOCBy Sebastian Bergmann
76. 76. PHPLOCBy Sebastian BergmannCommand Line Tool
77. 77. PHPLOCBy Sebastian BergmannCommand Line ToolSummarizes An EntireCodebase
78. 78. \$ phploc path/to/Drupal7/Directories: 73Files: 180Lines of Code (LOC): 63347Cyclomatic Complexity / Lines of Code: 0.04Comment Lines of Code (CLOC): 19321Non-Comment Lines of Code (NCLOC): 44026
79. 79. Namespaces: 0Interfaces: 1Traits: 0Classes: 38Abstract: 2 (5.26%)Concrete: 36 (94.74%)Average Class Length (NCLOC): 197
80. 80. Methods: 433Scope:Non-Static: 378 (87.30%)Static: 55 (12.70%)Visibility:Public: 255 (58.89%)Non-Public: 178 (41.11%)Average Method Length (NCLOC): 17Cyclomatic Complexity / Number of Methods: 3.02Anonymous Functions: 0Functions: 521Constants: 22Global constants: 15Class constants: 7
81. 81. PDepend
82. 82. PDependBy Manuel Pichler(Also German)
83. 83. PDependBy Manuel Pichler(Also German)Like PHPLOC, But Granular
84. 84. PDependBy Manuel Pichler(Also German)Like PHPLOC, But GranularLower Level Analysis
85. 85. Fanout: Describes Outward Dependencies- Describes Dependence on Other ClassesANDC: Average Num of Derived Classes- Describes How Much Inheritance Is UsedAHH: Average Hiearchy Height- Describes How Deep Of Inheritance Is Used
86. 86. PHPMD(Mess Detector)
87. 87. PHPMDBy Manuel Pichler(German)
88. 88. PHPMDBy Manuel Pichler(German)Finds "Messy" Parts Of Code
89. 89. PHPMDBy Manuel Pichler(German)Finds "Messy" Parts Of CodeFinds Rule Violations
90. 90. PHPMD RulesCodeSize- (CC, NPath, Number of Methods, Size of Methods, etc)Design- (Eval, Goto, Exit(), Inheritance Depth)Naming- (Short names, Inconsistent Names)Unused CodeControversial- (Superglobal Access, Naming Conventions)
91. 91. Prevent Complex CodeFrom Even Getting In!
92. 92. By ThemselvesUseful
93. 93. Over Time
94. 94. Over TimeInvaluable
95. 95. Drupal 8.x BranchNon-Comment Lines Of Code
96. 96. Drupal 8.x BranchNumber Of Classes
97. 97. Drupal 8.x BranchCyclomatic Complexity Per Method
98. 98. Drupal 8.x BranchCyclomatic Complexity Per Line
99. 99. Drupal 8.x Branch
100. 100. One More ThingTo Keep In Mind
101. 101. Anthony Ferrara@ircmaxellircmaxell@php.netanthony.ferrara@nbcuni.comblog.ircmaxell.comgithub.com/ircmaxellyoutube.com/ircmaxell