After days, weeks, or months of coding many developers don't know how to gauge the quality of their code. Adam Culp will introduce tools to grade, benchmark, and analyze code in an automated fashion allowing developers to write better quality software. He will explain key metrics to help understand what may need to be refactored, and use code smells to point out bugs before end-users discover them. Attendees will see how to use these tools, know where to find them, and be able to implement them in their own workflows.
2. 3
Does Your Code Measure Up?
●
Fan of iteration
– Pretty much everything requires iteration to do well:
●
Long distance running
●
Judo
●
Development
●
Evading project managers
●
Code Quality!
7. 8
Does Your Code Measure Up?
●
Why Measure?
– Highlight bugs
– Improve quality
●
Easier onboarding
●
Less reading, more writing
●
Testable
8. 9
Does Your Code Measure Up?
●
Why Measure?
– Highlight bugs
– Improve quality
●
Easier onboarding
●
Less reading, more writing
●
Testable
– Satisfied customers
●
Faster development
●
Less broken
9. 10
Does Your Code Measure Up?
●
Why Measure?
– Highlight bugs
– Improve quality
●
Easier onboarding
●
Less reading, more writing
●
Testable
– Satisfied customers
●
Faster development
●
Less broken
– Personal pride
10. 11
Does Your Code Measure Up?
●
Why Measure?
– Highlight bugs
– Improve quality
●
Easier onboarding
●
Less reading, more writing
●
Testable
– Satisfied customers
●
Faster development
●
Less broken
– Personal pride
– Higher salary
11. 12
Does Your Code Measure Up?
●
What To Measure?
– Cyclomatic complexity
●
“The count of the number of linearly independent paths through the
source code.” - wikipedia
●
Decision points
●
Less than 10 (personally less than 6)
13. 14
Does Your Code Measure Up?
●
What To Measure?
– Cyclomatic complexity
– Duplicate code
●
Rule of 3
14. 15
Does Your Code Measure Up?
●
What To Measure?
– Cyclomatic complexity
– Duplicate code
– Long classes
●
Less than 1,000 lines
●
Classes solve a (1) problem
15. 16
Does Your Code Measure Up?
●
What To Measure?
– Cyclomatic complexity
– Duplicate code
– Long classes
– Class Complexity
●
Less than 50
16. 17
Does Your Code Measure Up?
●
What To Measure?
– Cyclomatic complexity
– Duplicate code
– Long classes
– Class complexity
– Long methods
●
Less than 100 (personally less than 20)
●
Method should do one thing
17. 18
Does Your Code Measure Up?
●
What To Measure?
– Cyclomatic complexity
– Duplicate code
– Long classes
– Class complexity
– Long methods
– Unused variables
18. 19
Does Your Code Measure Up?
●
What To Measure?
– Cyclomatic complexity
– Duplicate code
– Long classes
– Class complexity
– Long methods
– Unused variables
– Lack or overuse of comments
●
Clear, concise, not explain bad code
20. 21
Does Your Code Measure Up?
●
What To Measure?
– Cyclomatic complexity
– Duplicate code
– Long classes
– Class complexity
– Long methods
– Unused variables
– Lack or overuse of comments
– Heavy global usage
21. 22
Does Your Code Measure Up?
●
What To Measure?
– Cyclomatic complexity
– Duplicate code
– Long classes
– Class complexity
– Long methods
– Unused variables
– Lack or overuse of comments
– Heavy global usage
– Npath complexity
●
Possible paths through code
●
Less than 200 paths
22. 23
Does Your Code Measure Up?
●
What To Measure?
– Cyclomatic complexity
– Duplicate code
– Long classes
– Class complexity
– Long methods
– Unused variables
– Lack or overuse of comments
– Heavy global usage
– Npath complexity
– Much, much, more
●
Code smells
23. 24
Does Your Code Measure Up?
●
Code “smells”
– What are “smells”?
●
Indications of spoiled code nearby
●
Not conclusive
●
The “smell” is not bad
24. 25
Does Your Code Measure Up?
●
Common Code “smells”
– “Smells” hinting a refactor may be needed:
●
Duplicate Code (rule of 3)
●
Long Methods
●
Large Class
●
Long Parameter (argument) List
●
Switch Statements – sacrifice polymorphism
●
Temporary Field/Variable
●
Comments – where comments cover bad code
29. 30
Does Your Code Measure Up?
●
Tools
– PHPqatools.org – DEPRECATED
●
PHPLoc
●
PHP_Depend - https://pdepend.org/
30. 31
Does Your Code Measure Up?
●
PHP_Depend Result
– Graphs and XML output
ANDC
AHH
NOP
NOC
NOM
LOC
CYCLO
NOM
CALLS
FANOUT9891
96646
66812
395815
23359
342
3192
0.585
0.442
9.333
7.318
16.945
0.169 0.102
4.137
Generated by PHP_DependLow Average High
39. 40
Does Your Code Measure Up?
●
Tools
– PHPqatools.org – DEPRECATED
– PHPMetrics
– PHP_Codesniffer
●
Create rules/sniffs to ensure standards are followed
●
From CLI, IDE, or via SCM hooks
41. 42
Does Your Code Measure Up?
●
Docker Hub
https://hub.docker.com/u/adamculp/
42. 43
Does Your Code Measure Up?
●
Commercial Tools
– Code Climate
●
Build from Git/Github repo
– Open = free
– Private = $
●
GPA – like in high school, simple
43. 44
Does Your Code Measure Up?
●
Commercial Tools
– Code Climate
– Scrutinizer
44. 45
Does Your Code Measure Up?
●
Commercial Tools
– Code Climate
– Scrutinizer
– Zend Server and Z-Ray
●
Debugging, Code tracing, Error reporting
45. 46
Does Your Code Measure Up?
●
Performance Tools
– Apache Bench (apache2-utils in apt)
●
How much traffic can you handle?
48. 49
Does Your Code Measure Up?
●
Conclusion
– Measure all the things!
– Don't fear results, share them
– Reduce complexity
– Leave code cleaner than you got it
– Learn to “smell” problems
– Use refactoring to fix shortcomings
– Love iteration!