SlideShare a Scribd company logo
1 of 60
Download to read offline
Measuring your code
   A talk by Nate Abele
        @nateabele

        nate.abele@gmail.com
Feedback

    http://joind.in/1601
Confession
Coercion, red bars & broken
windows
Continuous
Goal: Perfection
Or at the least, continuous
improvement
a.k.a.   (kaizen)
What people usually think
       Estimating costs
       Projecting deadlines
       Managerial BS!
Client Spec Sheet some paraphrased)
         (actual bullet points,
         Flash intro with no load time
         User account logins, password optional
         Ajax chat
         “Like Google”
...and my personal favorite


        Social network
Measurement is an essential element of
management; there is little chance of
controlling what we can not measure.
              - Wikipedia, “Software metric”
Wherefore... (WTF) ?
“Engineer” & “architect”
Cognitive Dissonance      *


       Engineers deal with tangible, immutable
       constraints, like gravity
       The practice of developing software is
       an inherently creative discipline
                                 * Thank you, Jones
Cognitive Dissonance
       Developer constraints (scope, schedule,
       budget) potentially / often in flux
       Software is inter-related; working on one
       part changes the others
       No project is exactly the same as another
Conclusion
       It’s not useful to measure high-level,
       intangible things like whole projects
       This is where scrum comes in handy
       Instead, we can use lower-level, more
       concrete measurements
What can we measure?
Code!!
More specifically...
         Unit test coverage
         Complexity
         Speed
         Documentation
More specifically...

         Standards conformance
         Refactoration!
Backing up...
          What is a metric?
     Measurement assigns numbers based on well-
     defined meaning

       - Sometimes the environment must be
         modified

       - Special development procedures that track
       various activities       - Wikipedia (paraphrased)

          You can cheat and use booleans, too
Notes on continuous integration
        A build system
        Runs on every code commit
        Runs tests
        Reports
Metric examples
PHP Code Sniffer
       PEAR Package:
       http://pear.php.net/package/PHP_CodeSniffer



       Checks conformance of a set of files against
       a series of classes called “sniffs”
PHP Code Sniffer
$ phpcs /path/to/code/myfile.php

FILE: /path/to/code/myfile.php
------------------------------------------------------------------------
FOUND 5 ERROR(S) AFFECTING 2 LINE(S)
------------------------------------------------------------------------
  2 | ERROR | Missing file doc comment
 47 | ERROR | Line not indented correctly; expected 4 spaces but found 1
 51 | ERROR | Missing function doc comment
 88 | ERROR | Line not indented correctly; expected 9 spaces but found 6
------------------------------------------------------------------------
PHP Code Sniffer
$ svn commit -m "Test" temp.php
Sending        temp.php
Transmitting file data .svn: Commit failed (details follow):
svn: 'pre-commit' hook failed with error output:

FILE: temp.php
--------------------------------------------------------------
FOUND 1 ERROR(S) AND 0 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------
 2 | ERROR | Missing file doc comment
--------------------------------------------------------------
This is important because things
are standardized
Measuring code complexity
       Cyclomatic complexity
         Directly measures the number of linearly
         independent paths through a program's
         source code.
         a.k.a. 1 + the number of times it branches
Measuring code complexity
  public function render() {
      $code = null;

      if (isset($this->headers['location']) && $this->status['code'] === 200) {
          $code = 302;
      }

      if (!$status = $this->status($code)) {
          throw new Exception('Invalid status code');
      }
      $this->_writeHeader($status);

      foreach ($this->headers as $name => $value) {
          $key = strtolower($name);

          if ($key == 'location') {
              $this->_writeHeader("Location: {$value}", $this->status['code']);
          } elseif ($key == 'download') {
              $this->_writeHeader('Content-Disposition: attachment; filename="' . $val
          } elseif (is_array($value)) {
              $this->_writeHeader(
                  array_map(function($v) use ($name) { return "{$name}: {$v}"; }, $val
              );
          } elseif (!is_numeric($name)) {
              $this->_writeHeader("{$name}: {$value}");
          }
      }
  }
Measuring code coverage
Measuring documentation coverage
    Check it out @   http://thechaw.com/api_generator
Measuring documentation coverage
       Check it out:
       http://thechaw.com/api_generator



       A series of rules
       Assigns weights based on docblock content
       and various docblock tags
Measuring documentation coverage
       Basic checks:
          Do doc tags exist?
          Incomplete @param tags?
          Do @param tags match actual params?
          Does it have a @link to the man page?
Profiling
Profiling
       Get timing / memory usage on every test run
       Granular, get statistics per test method
       Using continuous integration, code is profiled
       on each commit, all on a granular level
Case study
CakePHP 1.2 release cycle




1.2 alpha   1.2 beta   1.2 RC1   1.2 RC2   1.2 RC3   1.2 RC4
Metrics are your canary in the coal
mine of your development cycle
By tracking profiler stats (and other metrics),
we can see trends over time, and catch
problems before they become problems
Plus, who doesn’t like pretty graphs?
Finding things to measure
        Lithium Inspector class
        Lithium Parser class
        Based on the awesome work of Sean Coates
        http://github.com/scoates/tokalizer
Finding things to measure
Finding things to measure
Finding things to measure
Finding things to measure
Finding things to measure
In a dynamic language like PHP, this
 is a hard problem.
However, deep code introspection
 allows us to ask & answer some
very interesting questions
Project mess detection in PHPUnit
Beyond copy-paste detection & into
 pattern recognition
High-level refactoring tools
Can “good code” be quantified??
When is “good enough”... good enough?
Technical debt
Incentives and social coercion
Choose your own adventure!
Go write better code

More Related Content

Viewers also liked

Viewers also liked (9)

Clean Code
Clean CodeClean Code
Clean Code
 
Measuring Your Code
Measuring Your CodeMeasuring Your Code
Measuring Your Code
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3
 
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionLithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
 
The State of Lithium
The State of LithiumThe State of Lithium
The State of Lithium
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
 
The SQALE method: Meaningful insights into your Technical Debt
The SQALE method: Meaningful insights into your Technical DebtThe SQALE method: Meaningful insights into your Technical Debt
The SQALE method: Meaningful insights into your Technical Debt
 

Similar to Measuring Your Code 2.0

Working Effectively With Legacy Perl Code
Working Effectively With Legacy Perl CodeWorking Effectively With Legacy Perl Code
Working Effectively With Legacy Perl Code
erikmsp
 
Class 6: Introduction to web technology entrepreneurship
Class 6: Introduction to web technology entrepreneurshipClass 6: Introduction to web technology entrepreneurship
Class 6: Introduction to web technology entrepreneurship
allanchao
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
Michelangelo van Dam
 
QA Fest 2019. Дмитрий Собко. Testing Big Data solutions fast and furiously
QA Fest 2019. Дмитрий Собко. Testing Big Data solutions fast and furiouslyQA Fest 2019. Дмитрий Собко. Testing Big Data solutions fast and furiously
QA Fest 2019. Дмитрий Собко. Testing Big Data solutions fast and furiously
QAFest
 

Similar to Measuring Your Code 2.0 (20)

Measuring Your Code
Measuring Your CodeMeasuring Your Code
Measuring Your Code
 
The "Holy Grail" of Dev/Ops
The "Holy Grail" of Dev/OpsThe "Holy Grail" of Dev/Ops
The "Holy Grail" of Dev/Ops
 
PVS-Studio and static code analysis technique
PVS-Studio and static code analysis techniquePVS-Studio and static code analysis technique
PVS-Studio and static code analysis technique
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and SparkVital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
 
Working Effectively With Legacy Perl Code
Working Effectively With Legacy Perl CodeWorking Effectively With Legacy Perl Code
Working Effectively With Legacy Perl Code
 
We continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellWe continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShell
 
Class 6: Introduction to web technology entrepreneurship
Class 6: Introduction to web technology entrepreneurshipClass 6: Introduction to web technology entrepreneurship
Class 6: Introduction to web technology entrepreneurship
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 
Looking for Bugs in MonoDevelop
Looking for Bugs in MonoDevelopLooking for Bugs in MonoDevelop
Looking for Bugs in MonoDevelop
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
2010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week12010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week1
 
Hands on Mahout!
Hands on Mahout!Hands on Mahout!
Hands on Mahout!
 
QA Fest 2019. Дмитрий Собко. Testing Big Data solutions fast and furiously
QA Fest 2019. Дмитрий Собко. Testing Big Data solutions fast and furiouslyQA Fest 2019. Дмитрий Собко. Testing Big Data solutions fast and furiously
QA Fest 2019. Дмитрий Собко. Testing Big Data solutions fast and furiously
 
Testing Big Data solutions fast and furiously
Testing Big Data solutions fast and furiouslyTesting Big Data solutions fast and furiously
Testing Big Data solutions fast and furiously
 
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
 
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Parasoft .TEST, Write better C# Code Using  Data Flow Analysis Parasoft .TEST, Write better C# Code Using  Data Flow Analysis
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)
 

Recently uploaded

Recently uploaded (20)

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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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?
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.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
 

Measuring Your Code 2.0