SlideShare une entreprise Scribd logo
1  sur  49
Does Your Code
Measure Up?
By:
Adam Culp
Twitter: @adamculp
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!
4
Does Your Code Measure Up?
●
How To Measure?
– Not productive
5
Does Your Code Measure Up?
●
Bad Music
– Not a song writer
6
Does Your Code Measure Up?
●
How To Measure?
– More accurate, quantifiable
7
Does Your Code Measure Up?
●
Why Measure?
– Highlight bugs
8
Does Your Code Measure Up?
●
Why Measure?
– Highlight bugs
– Improve quality
●
Easier onboarding
●
Less reading, more writing
●
Testable
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
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
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
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
Does Your Code Measure Up?
●
Cyclomatic Complexity Example
14
Does Your Code Measure Up?
●
What To Measure?
– Cyclomatic complexity
– Duplicate code
●
Rule of 3
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
16
Does Your Code Measure Up?
●
What To Measure?
– Cyclomatic complexity
– Duplicate code
– Long classes
– Class Complexity
●
Less than 50
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
18
Does Your Code Measure Up?
●
What To Measure?
– Cyclomatic complexity
– Duplicate code
– Long classes
– Class complexity
– Long methods
– Unused variables
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
Does Your Code Measure Up?
●
Comment Example
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
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
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
24
Does Your Code Measure Up?
●
Code “smells”
– What are “smells”?
●
Indications of spoiled code nearby
●
Not conclusive
●
The “smell” is not bad
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
26
Does Your Code Measure Up?
●
Tools
– PHPqatools.org – DEPRECATED
27
Does Your Code Measure Up?
●
Tools
– PHPqatools.org – DEPRECATED
– https://github.com/exakat/php-static-analysis-tools
28
Does Your Code Measure Up?
●
Tools
– PHPqatools.org – DEPRECATED
●
PHPLoc
29
Does Your Code Measure Up?
●
PHPLoc Results
30
Does Your Code Measure Up?
●
Tools
– PHPqatools.org – DEPRECATED
●
PHPLoc
●
PHP_Depend - https://pdepend.org/
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
32
Does Your Code Measure Up?
●
Tools
– PHPqatools.org – DEPRECATED
●
PHPLoc
●
PHP_Depend
●
PHP Copy/Paste Detector
33
Does Your Code Measure Up?
●
PHP Copy/Paste Detector Result
34
Does Your Code Measure Up?
●
Tools
– PHPqatools.org – DEPRECATED
●
PHPLoc
●
PHP_Depend
●
PHP Copy/Paste Detector
●
PHP Mess Detector
– Codesize
35
Does Your Code Measure Up?
●
PHP Mess Detector Result (codesize)
36
Does Your Code Measure Up?
●
Tools
– PHPqatools.org – DEPRECATED
●
PHPLoc
●
PHP_Depend
●
PHP Copy/Paste Detector
●
PHP Mess Detector
– Codesize
– Unused
37
Does Your Code Measure Up?
●
Tools
– PHPqatools.org – DEPRECATED
●
PHPLoc
●
PHP_Depend
●
PHP Copy/Paste Detector
●
PHP Mess Detector
– Codesize
– Unused
●
PHP Dead Code Detector
– Searches for code no longer used
38
Does Your Code Measure Up?
●
Tools
– PHPqatools.org – DEPRECATED
– PHPMetrics
●
http://phpmetrics.org
39
Does Your Code Measure Up?
●
PHPMetrics Results
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
Does Your Code Measure Up?
●
Containerized Tools
– PHPLoc
– PHPDepend
– PHPMessDetector
– PHPCopyPasteDetector
– PHPMetrics
– PHP_Codesniffer
https://github.com/adamculp/php-code-quality
https://hub.docker.com/u/adamculp/
42
Does Your Code Measure Up?
●
Docker Hub
https://hub.docker.com/u/adamculp/
43
Does Your Code Measure Up?
●
Commercial Tools
– Code Climate
●
Build from Git/Github repo
– Open = free
– Private = $
●
GPA – like in high school, simple
44
Does Your Code Measure Up?
●
Commercial Tools
– Code Climate
– Scrutinizer
45
Does Your Code Measure Up?
●
Commercial Tools
– Code Climate
– Scrutinizer
– Zend Server and Z-Ray
●
Debugging, Code tracing, Error reporting
46
Does Your Code Measure Up?
●
Performance Tools
– Apache Bench (apache2-utils in apt)
●
How much traffic can you handle?
47
Does Your Code Measure Up?
●
Apache Bench Result
48
Does Your Code Measure Up?
●
Realtime profiling
– Z-Ray
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!
50
●
Thank you!
– http://phpqatools.org https://github.com/exakat/php-static-analysis-tools
– http://phpmetrics.org
– https://github.com/adamculp/php-code-quality
– http://zend.com
– http://codeclimate.com
– Please rate
Adam Culp
http://www.geekyboy.com
http://RunGeekRadio.com
Twitter @adamculp

Contenu connexe

Tendances

Concepts of Functional Programming for Java Brains (2010)
Concepts of Functional Programming for Java Brains (2010)Concepts of Functional Programming for Java Brains (2010)
Concepts of Functional Programming for Java Brains (2010)
Peter Kofler
 
Java User Groups in Austria (2013)
Java User Groups in Austria (2013)Java User Groups in Austria (2013)
Java User Groups in Austria (2013)
Peter Kofler
 
Coding Dojo: Mars Rover (2014)
Coding Dojo: Mars Rover (2014)Coding Dojo: Mars Rover (2014)
Coding Dojo: Mars Rover (2014)
Peter Kofler
 
Software Craftsmanship Journeyman Tour (2013)
Software Craftsmanship Journeyman Tour (2013)Software Craftsmanship Journeyman Tour (2013)
Software Craftsmanship Journeyman Tour (2013)
Peter Kofler
 
The Brutal Refactoring Game (2013)
The Brutal Refactoring Game (2013)The Brutal Refactoring Game (2013)
The Brutal Refactoring Game (2013)
Peter Kofler
 

Tendances (20)

Concepts of Functional Programming for Java Brains (2010)
Concepts of Functional Programming for Java Brains (2010)Concepts of Functional Programming for Java Brains (2010)
Concepts of Functional Programming for Java Brains (2010)
 
GDCR15 in Las Palmas, Gran Canaria
GDCR15 in Las Palmas, Gran CanariaGDCR15 in Las Palmas, Gran Canaria
GDCR15 in Las Palmas, Gran Canaria
 
Pair Programming (2015)
Pair Programming (2015)Pair Programming (2015)
Pair Programming (2015)
 
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
 
Java User Groups in Austria (2013)
Java User Groups in Austria (2013)Java User Groups in Austria (2013)
Java User Groups in Austria (2013)
 
Coding Dojo: Functional Calisthenics (2016)
Coding Dojo: Functional Calisthenics (2016)Coding Dojo: Functional Calisthenics (2016)
Coding Dojo: Functional Calisthenics (2016)
 
Coding Dojo: Mars Rover (2014)
Coding Dojo: Mars Rover (2014)Coding Dojo: Mars Rover (2014)
Coding Dojo: Mars Rover (2014)
 
Coding Dojo: Bank OCR Outside-In (2015)
Coding Dojo: Bank OCR Outside-In (2015)Coding Dojo: Bank OCR Outside-In (2015)
Coding Dojo: Bank OCR Outside-In (2015)
 
Coding Dojo: Baby Steps Push Challenge (2021)
Coding Dojo: Baby Steps Push Challenge (2021)Coding Dojo: Baby Steps Push Challenge (2021)
Coding Dojo: Baby Steps Push Challenge (2021)
 
TDD as if You Meant It (2013)
TDD as if You Meant It (2013)TDD as if You Meant It (2013)
TDD as if You Meant It (2013)
 
Outside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDDOutside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDD
 
Software Craftsmanship Journeyman Tour (2013)
Software Craftsmanship Journeyman Tour (2013)Software Craftsmanship Journeyman Tour (2013)
Software Craftsmanship Journeyman Tour (2013)
 
AgilePT2012 PGMADS
AgilePT2012 PGMADSAgilePT2012 PGMADS
AgilePT2012 PGMADS
 
Extract Method Refactoring Workshop (2016)
Extract Method Refactoring Workshop (2016)Extract Method Refactoring Workshop (2016)
Extract Method Refactoring Workshop (2016)
 
The Brutal Refactoring Game (2013)
The Brutal Refactoring Game (2013)The Brutal Refactoring Game (2013)
The Brutal Refactoring Game (2013)
 
Clean Readable Specifications (ETC 2016)
Clean Readable Specifications (ETC 2016)Clean Readable Specifications (ETC 2016)
Clean Readable Specifications (ETC 2016)
 
Code Retreat Venice (2016)
Code Retreat Venice (2016)Code Retreat Venice (2016)
Code Retreat Venice (2016)
 
Mob Programming (2016)
Mob Programming (2016)Mob Programming (2016)
Mob Programming (2016)
 
Refactoring the Tennis Kata v2 (2016)
Refactoring the Tennis Kata v2 (2016)Refactoring the Tennis Kata v2 (2016)
Refactoring the Tennis Kata v2 (2016)
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 

En vedette

En vedette (8)

Virtualizing Development
Virtualizing DevelopmentVirtualizing Development
Virtualizing Development
 
Accidental professional
Accidental professionalAccidental professional
Accidental professional
 
Foundations of Zend Framework
Foundations of Zend FrameworkFoundations of Zend Framework
Foundations of Zend Framework
 
Zend expressive workshop
Zend expressive workshopZend expressive workshop
Zend expressive workshop
 
Expressive Microservice Framework Blastoff
Expressive Microservice Framework BlastoffExpressive Microservice Framework Blastoff
Expressive Microservice Framework Blastoff
 
Refactoring Legacy Code
Refactoring Legacy CodeRefactoring Legacy Code
Refactoring Legacy Code
 
Practical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsPractical PHP Deployment with Jenkins
Practical PHP Deployment with Jenkins
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101
 

Similaire à Does Your Code Measure Up?

Good code, Bad Code
Good code, Bad CodeGood code, Bad Code
Good code, Bad Code
josedasilva
 
Coding Dojo: Roman Numerals (2014)
Coding Dojo: Roman Numerals (2014)Coding Dojo: Roman Numerals (2014)
Coding Dojo: Roman Numerals (2014)
Peter Kofler
 
Coding Dojo: String Calculator (2013)
Coding Dojo: String Calculator (2013)Coding Dojo: String Calculator (2013)
Coding Dojo: String Calculator (2013)
Peter Kofler
 

Similaire à Does Your Code Measure Up? (20)

Containing Quality
Containing QualityContaining Quality
Containing Quality
 
Code quality and its business value, Nikita Belov
Code quality and its business value, Nikita BelovCode quality and its business value, Nikita Belov
Code quality and its business value, Nikita Belov
 
Good code, Bad Code
Good code, Bad CodeGood code, Bad Code
Good code, Bad Code
 
Journey to Google
Journey to GoogleJourney to Google
Journey to Google
 
Code Reviews in Python - PyZh
Code Reviews in Python - PyZhCode Reviews in Python - PyZh
Code Reviews in Python - PyZh
 
Clean application development (talk)
Clean application development (talk)Clean application development (talk)
Clean application development (talk)
 
DOES15 - Mirco Hering - Adopting DevOps Practices for Systems of Record – An ...
DOES15 - Mirco Hering - Adopting DevOps Practices for Systems of Record – An ...DOES15 - Mirco Hering - Adopting DevOps Practices for Systems of Record – An ...
DOES15 - Mirco Hering - Adopting DevOps Practices for Systems of Record – An ...
 
Mirco hering devops for systems of record final
Mirco hering devops for systems of record finalMirco hering devops for systems of record final
Mirco hering devops for systems of record final
 
Linters for frontend code review
Linters for frontend code reviewLinters for frontend code review
Linters for frontend code review
 
Achieving Technical Excellence in Your Software Teams - from Devternity
Achieving Technical Excellence in Your Software Teams - from Devternity Achieving Technical Excellence in Your Software Teams - from Devternity
Achieving Technical Excellence in Your Software Teams - from Devternity
 
Clean application development tutorial
Clean application development tutorialClean application development tutorial
Clean application development tutorial
 
Managing Technical Debt
Managing Technical DebtManaging Technical Debt
Managing Technical Debt
 
Coding Dojo: Roman Numerals (2014)
Coding Dojo: Roman Numerals (2014)Coding Dojo: Roman Numerals (2014)
Coding Dojo: Roman Numerals (2014)
 
Code Review
Code ReviewCode Review
Code Review
 
Improve existing code with confidence, supported by unit tests
Improve existing code with confidence, supported by unit testsImprove existing code with confidence, supported by unit tests
Improve existing code with confidence, supported by unit tests
 
How to quickly add a safety net to a legacy codebase
How to quickly add a safety net to a legacy codebaseHow to quickly add a safety net to a legacy codebase
How to quickly add a safety net to a legacy codebase
 
PHP Code Quality
PHP Code QualityPHP Code Quality
PHP Code Quality
 
Coding Dojo: String Calculator (2013)
Coding Dojo: String Calculator (2013)Coding Dojo: String Calculator (2013)
Coding Dojo: String Calculator (2013)
 
You cant be agile if your code sucks
You cant be agile if your code sucksYou cant be agile if your code sucks
You cant be agile if your code sucks
 
Refactoring code in .net
Refactoring code in .netRefactoring code in .net
Refactoring code in .net
 

Plus de Adam Culp

Plus de Adam Culp (17)

Hypermedia
HypermediaHypermedia
Hypermedia
 
Putting legacy to REST with middleware
Putting legacy to REST with middlewarePutting legacy to REST with middleware
Putting legacy to REST with middleware
 
php-1701-a
php-1701-aphp-1701-a
php-1701-a
 
Release your refactoring superpower
Release your refactoring superpowerRelease your refactoring superpower
Release your refactoring superpower
 
Developing PHP Applications Faster
Developing PHP Applications FasterDeveloping PHP Applications Faster
Developing PHP Applications Faster
 
Debugging elephpants
Debugging elephpantsDebugging elephpants
Debugging elephpants
 
Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developers
 
Vagrant for Virtualized Development
Vagrant for Virtualized DevelopmentVagrant for Virtualized Development
Vagrant for Virtualized Development
 
Using an API
Using an APIUsing an API
Using an API
 
Puppet and Vagrant in development
Puppet and Vagrant in developmentPuppet and Vagrant in development
Puppet and Vagrant in development
 
Refactoring PHP
Refactoring PHPRefactoring PHP
Refactoring PHP
 
Selenium testing IDE 101
Selenium testing IDE 101Selenium testing IDE 101
Selenium testing IDE 101
 
Intro to OOP and new features in PHP 5.3
Intro to OOP and new features in PHP 5.3Intro to OOP and new features in PHP 5.3
Intro to OOP and new features in PHP 5.3
 
Development Environment Tips
Development Environment TipsDevelopment Environment Tips
Development Environment Tips
 
Getting your project_started
Getting your project_startedGetting your project_started
Getting your project_started
 
PHP and PDFLib
PHP and PDFLibPHP and PDFLib
PHP and PDFLib
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Does Your Code Measure Up?

  • 1. Does Your Code Measure Up? By: Adam Culp Twitter: @adamculp
  • 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!
  • 3. 4 Does Your Code Measure Up? ● How To Measure? – Not productive
  • 4. 5 Does Your Code Measure Up? ● Bad Music – Not a song writer
  • 5. 6 Does Your Code Measure Up? ● How To Measure? – More accurate, quantifiable
  • 6. 7 Does Your Code Measure Up? ● Why Measure? – Highlight bugs
  • 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)
  • 12. 13 Does Your Code Measure Up? ● Cyclomatic Complexity Example
  • 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
  • 19. 20 Does Your Code Measure Up? ● Comment Example
  • 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
  • 25. 26 Does Your Code Measure Up? ● Tools – PHPqatools.org – DEPRECATED
  • 26. 27 Does Your Code Measure Up? ● Tools – PHPqatools.org – DEPRECATED – https://github.com/exakat/php-static-analysis-tools
  • 27. 28 Does Your Code Measure Up? ● Tools – PHPqatools.org – DEPRECATED ● PHPLoc
  • 28. 29 Does Your Code Measure Up? ● PHPLoc Results
  • 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
  • 31. 32 Does Your Code Measure Up? ● Tools – PHPqatools.org – DEPRECATED ● PHPLoc ● PHP_Depend ● PHP Copy/Paste Detector
  • 32. 33 Does Your Code Measure Up? ● PHP Copy/Paste Detector Result
  • 33. 34 Does Your Code Measure Up? ● Tools – PHPqatools.org – DEPRECATED ● PHPLoc ● PHP_Depend ● PHP Copy/Paste Detector ● PHP Mess Detector – Codesize
  • 34. 35 Does Your Code Measure Up? ● PHP Mess Detector Result (codesize)
  • 35. 36 Does Your Code Measure Up? ● Tools – PHPqatools.org – DEPRECATED ● PHPLoc ● PHP_Depend ● PHP Copy/Paste Detector ● PHP Mess Detector – Codesize – Unused
  • 36. 37 Does Your Code Measure Up? ● Tools – PHPqatools.org – DEPRECATED ● PHPLoc ● PHP_Depend ● PHP Copy/Paste Detector ● PHP Mess Detector – Codesize – Unused ● PHP Dead Code Detector – Searches for code no longer used
  • 37. 38 Does Your Code Measure Up? ● Tools – PHPqatools.org – DEPRECATED – PHPMetrics ● http://phpmetrics.org
  • 38. 39 Does Your Code Measure Up? ● PHPMetrics Results
  • 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
  • 40. 41 Does Your Code Measure Up? ● Containerized Tools – PHPLoc – PHPDepend – PHPMessDetector – PHPCopyPasteDetector – PHPMetrics – PHP_Codesniffer https://github.com/adamculp/php-code-quality https://hub.docker.com/u/adamculp/
  • 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?
  • 46. 47 Does Your Code Measure Up? ● Apache Bench Result
  • 47. 48 Does Your Code Measure Up? ● Realtime profiling – Z-Ray
  • 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!
  • 49. 50 ● Thank you! – http://phpqatools.org https://github.com/exakat/php-static-analysis-tools – http://phpmetrics.org – https://github.com/adamculp/php-code-quality – http://zend.com – http://codeclimate.com – Please rate Adam Culp http://www.geekyboy.com http://RunGeekRadio.com Twitter @adamculp