SlideShare a Scribd company logo
Measuring your code
   A talk by Nate Abele
        @nateabele

        nate.abele@gmail.com
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”
Measuring Your Code
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
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
        CakePHP Inspector class
        CakePHP 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??
Good
     vs.
good enough
     vs.
the economy

More Related Content

PPTX
Testing with laravel
Derek Binkley
 
PPTX
Why is dev ops for machine learning so different
Ryan Dawson
 
PPTX
PHPUnit - Unit testing
Nguyễn Đào Thiên Thư
 
PPTX
XP in the full stack
XP Conference India
 
PDF
javabasics_ programming development chapter01
Udeshg90
 
PDF
Refactoring Legacy Code
Adam Culp
 
PPT
TDD And Refactoring
Naresh Jain
 
PDF
Refactoring 101
Adam Culp
 
Testing with laravel
Derek Binkley
 
Why is dev ops for machine learning so different
Ryan Dawson
 
PHPUnit - Unit testing
Nguyễn Đào Thiên Thư
 
XP in the full stack
XP Conference India
 
javabasics_ programming development chapter01
Udeshg90
 
Refactoring Legacy Code
Adam Culp
 
TDD And Refactoring
Naresh Jain
 
Refactoring 101
Adam Culp
 

What's hot (19)

PPTX
Refactoring legacy code driven by tests - ENG
Luca Minudel
 
ODP
Tdd in php a brief example
Jeremy Kendall
 
PPTX
IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자
Taeyeop Kim
 
PDF
TDD and Simple Design Workshop - Session 1 - March 2019
Paulo Clavijo
 
PDF
Dutch PHP Conference 2013: Distilled
Zumba Fitness - Technology Team
 
PDF
Programming in Java: Getting Started
Martin Chapman
 
PPT
Coldfusion
Ram
 
PDF
Joomla Code Quality Control and Automation Testing
Shyam Sunder Verma
 
PPTX
Programming Paradigm & Languages
Gaditek
 
PPTX
Pre processor directives in c
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Test Driven Development Methodology and Philosophy
Vijay Kumbhar
 
PPTX
C#
Gokul Ram
 
PDF
Droidcon Summary 2021
Bartosz Kosarzycki
 
PPTX
C# 101: Intro to Programming with C#
Hawkman Academy
 
PPTX
TDD - Test Driven Development
Tung Nguyen Thanh
 
PPTX
Switch case looping
Cherimay Batallones
 
PDF
C++ 11 Style : A Touch of Class
Yogendra Rampuria
 
PDF
NDC London 2014: Erlang Patterns Matching Business Needs
Torben Hoffmann
 
ODP
Java code coverage with JCov. Implementation details and use cases.
Alexandre (Shura) Iline
 
Refactoring legacy code driven by tests - ENG
Luca Minudel
 
Tdd in php a brief example
Jeremy Kendall
 
IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자
Taeyeop Kim
 
TDD and Simple Design Workshop - Session 1 - March 2019
Paulo Clavijo
 
Dutch PHP Conference 2013: Distilled
Zumba Fitness - Technology Team
 
Programming in Java: Getting Started
Martin Chapman
 
Coldfusion
Ram
 
Joomla Code Quality Control and Automation Testing
Shyam Sunder Verma
 
Programming Paradigm & Languages
Gaditek
 
Test Driven Development Methodology and Philosophy
Vijay Kumbhar
 
Droidcon Summary 2021
Bartosz Kosarzycki
 
C# 101: Intro to Programming with C#
Hawkman Academy
 
TDD - Test Driven Development
Tung Nguyen Thanh
 
Switch case looping
Cherimay Batallones
 
C++ 11 Style : A Touch of Class
Yogendra Rampuria
 
NDC London 2014: Erlang Patterns Matching Business Needs
Torben Hoffmann
 
Java code coverage with JCov. Implementation details and use cases.
Alexandre (Shura) Iline
 
Ad

Similar to Measuring Your Code (20)

PDF
Measuring Your Code
Nate Abele
 
PDF
Measuring Your Code 2.0
Nate Abele
 
PPT
Ensuring code quality
MikhailVladimirov
 
PDF
Improving the accuracy and reliability of data analysis code
Johan Carlin
 
PDF
Machine programming
DESMOND YUEN
 
PPT
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Engineering Software Lab
 
PDF
Software Engineering for Data Scientists (MEAP V2) Andrew Treadway
carvobunns30
 
PPT
Architecture presentation 4
Anoushiravan M. Ghamsari
 
PDF
Illustrated Code (ASE 2021)
CISPA Helmholtz Center for Information Security
 
PDF
Class 6: Introduction to web technology entrepreneurship
allanchao
 
PPT
Software testing presentation for engineering students of computer science
AmaanAli86
 
ODP
Building Scalable Development Environments
Shahar Evron
 
PDF
Software Defect Prevention via Continuous Inspection
Josh Gough
 
PPTX
DevOps interview questions and answers
HopeTutors1
 
PDF
Put Your Hands in the Mud: What Technique, Why, and How
Massimiliano Di Penta
 
PPTX
Do Your Homework! Writing tests for Data Science and Stochastic Code - David ...
PyData
 
PPT
Aspect Oriented Software Development
Jignesh Patel
 
PDF
Cloud continuous integration- A distributed approach using distinct services
André Agostinho
 
PPTX
Deploying more technology to shift from agility to anti-fragility
Spyros Lambrinidis
 
PPTX
Continuous Integration and development environment approach
Aleksandr Tsertkov
 
Measuring Your Code
Nate Abele
 
Measuring Your Code 2.0
Nate Abele
 
Ensuring code quality
MikhailVladimirov
 
Improving the accuracy and reliability of data analysis code
Johan Carlin
 
Machine programming
DESMOND YUEN
 
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Engineering Software Lab
 
Software Engineering for Data Scientists (MEAP V2) Andrew Treadway
carvobunns30
 
Architecture presentation 4
Anoushiravan M. Ghamsari
 
Class 6: Introduction to web technology entrepreneurship
allanchao
 
Software testing presentation for engineering students of computer science
AmaanAli86
 
Building Scalable Development Environments
Shahar Evron
 
Software Defect Prevention via Continuous Inspection
Josh Gough
 
DevOps interview questions and answers
HopeTutors1
 
Put Your Hands in the Mud: What Technique, Why, and How
Massimiliano Di Penta
 
Do Your Homework! Writing tests for Data Science and Stochastic Code - David ...
PyData
 
Aspect Oriented Software Development
Jignesh Patel
 
Cloud continuous integration- A distributed approach using distinct services
André Agostinho
 
Deploying more technology to shift from agility to anti-fragility
Spyros Lambrinidis
 
Continuous Integration and development environment approach
Aleksandr Tsertkov
 
Ad

More from Nate Abele (9)

PDF
The State of Lithium
Nate Abele
 
PDF
The Zen of Lithium
Nate Abele
 
PDF
Building Lithium Apps
Nate Abele
 
PDF
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Nate Abele
 
PDF
Building Apps with MongoDB
Nate Abele
 
PDF
Practical PHP 5.3
Nate Abele
 
PDF
Lithium: The Framework for People Who Hate Frameworks
Nate Abele
 
PDF
The Origin of Lithium
Nate Abele
 
PDF
Doin' It Rong
Nate Abele
 
The State of Lithium
Nate Abele
 
The Zen of Lithium
Nate Abele
 
Building Lithium Apps
Nate Abele
 
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Nate Abele
 
Building Apps with MongoDB
Nate Abele
 
Practical PHP 5.3
Nate Abele
 
Lithium: The Framework for People Who Hate Frameworks
Nate Abele
 
The Origin of Lithium
Nate Abele
 
Doin' It Rong
Nate Abele
 

Recently uploaded (20)

PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
The Future of Artificial Intelligence (AI)
Mukul
 

Measuring Your Code