SlideShare a Scribd company logo
Measure twice, cut once
SOFTWARE METRICS
@matthiasmullie
Software metrics
Make software measurable
instead of relying on intuition.
Software metrics
Presentation titleSoftware metrics
Presentation titleSoftware metrics
Presentation titleSoftware metrics
Software metrics
COMPLEXITY
Every code path adds complexity
Counts # of code paths
Software metrics » Complexity
Cyclomatic complexity
• Analyze control flow
• Start at 1
• Increase at every decision path

(if, for, case, …)
Software metrics » Complexity
Cyclomatic complexity
if ($user->isLoggedIn()) {
echo 'Welcome back, ' . $user->getName();
} else {
echo 'Hi there, stranger!';
}
Cyclomatic complexity = 2
Software metrics » Complexity
Cyclomatic complexity
Every code path adds complexity
Counts # possible outcomes
Software metrics » Complexity
NPath complexity
Software metrics » Complexity
NPath complexity
if ($user->getSalutation()) {
echo $user->getSalutation().' ';
}
if ($user->getName()) {
echo $user->getName();
} else {
echo 'anon';
}
Outcomes: • $salutation anon
• anon
• $salutation $name
• $name
Every operation adds complexity
Software metrics » Complexity
Halstead measures
• Analyze vocabulary
• Count amount of operators

(+, -, =, &&, ... and reserved words,

like if and for)
• Count amount of operands

(values, variables & function names)
Software metrics » Complexity
Halstead measures
if ($user->isLoggedIn()) {
echo 'Welcome back, ' . $user->getName();
} else {
echo 'Hi there, stranger!';
}
Operands = 4 (4 unique)
Software metrics » Complexity
Halstead measures
if ($user->isLoggedIn()) {
echo 'Welcome back, ' . $user->getName();
} else {
echo 'Hi there, stranger!';
}
Operators = 11 (7 unique)
Software metrics » Complexity
Halstead measures
Engineered to match human analysis
Software metrics » Complexity
Maintainability index
Combination of:
• Cyclomatic complexity
• Halstead measures
• Lines of code
Software metrics » Complexity
Maintainability index
Metrics for matthiasmullie/minify, MatthiasMullieMinifyJS::stripWhitespace
See https://www.cauditor.org/matthiasmullie/minify/c17eb048daa44b43fa98bfa405147e77a040df76/metrics
Software metrics » Complexity
Maintainability index
Questions?
Software metrics » Complexity
Software metrics
COUPLING
Amount of incoming dependencies
= other classes using this one
Common for core functionality
Software metrics » Coupling
Afferent coupling
class Afferent
{
function __construct() {}
}
class Efferent
{
function __construct(Afferent $a) {}
}
Afferent: 1, Efferent: 0
Software metrics » Coupling
Afferent coupling
Changes here may break things elsewhere
Must be stable & thoroughly tested
Software metrics » Coupling
Afferent coupling
Amount of outgoing dependencies
= other classes being used
Common for controllers
Software metrics » Coupling
Efferent coupling
class Afferent
{
function __construct() {}
}
class Efferent
{
function __construct(Afferent $a) {}
}
Afferent: 0, Efferent: 1
Software metrics » Coupling
Efferent coupling
• Harder to read/maintain
• Harder to reuse
• Harder to test in isolation
• Brittle
Software metrics » Coupling
Efferent coupling
Changes elsewhere may break things here
Probably violates single responsibility
principle
Software metrics » Coupling
Efferent coupling
= efferent coupling / total coupling
= efferent coupling / (efferent + afferent)
Resilience to change
Software metrics » Coupling
Instability
High efferent coupling
= likely to be impacted by changes in

= other classes
= not stable
Software metrics » Coupling
Instability
Low afferent coupling
= change is easy because there isn’t much

= that depends on this
= not stable
Software metrics » Coupling
Instability
Stable = good
… as long as you don’t need to change
the implementation!
Software metrics » Coupling
Instability
Aim for extremes, make classes as stable
or unstable as possible!
Unstables can be refactored/decomposed
later. Better than having dependencies
everywhere.
Software metrics » Coupling
Instability
Counts # of ancestors
Software metrics » Coupling
Depth of inheritance
class Ancestor {}
DIT: 0
class Descendant1 extends Ancestor {}
DIT: 1
class Descendant2 extends Descendant1 {}
DIT: 2
Software metrics » Coupling
Depth of inheritance
Inheritance is not bad!
• Code reuse
• Polymorphism
Software metrics » Coupling
Depth of inheritance
But too much is!
• Less stable: change in ancestor can
affect descendants
• More complexity: methods of all
ancestors are inherited
Software metrics » Coupling
Depth of inheritance
Questions?
Software metrics » Coupling
WHY WOULD I CARE?
Software metrics
Presentation titleSoftware metrics » Usage
Which would you rather maintain?
Presentation titleSoftware metrics » Usage
Software metrics » Usage
Complexity
This guy has
something going on!
Let’s see…
It’s not too crazy! But:
• Recursion
• 3 loops
• 4 conditions
• Callback function
Software metrics » Usage
Complexity
Method does too much:
• Data transformation
• Processing
• Cleanup
Hard to test & prove right!
Software metrics » Usage
Complexity
Software metrics » Usage
Complexity
This guy
has a lot
going on…
Presentation titleSoftware metrics
Software metrics » Usage
Coupling
• Lots of outgoing
dependencies
• Some inheritance
Very brittle!
Changes in any of these
could affect this class!
Software metrics » Usage
Coupling
Software metrics » Usage
Refactoring
• 1000+ LOC class
• Pretty complex
• Very unstable
• Self-contained, barely
reusable
Software metrics » ObservationsSoftware metrics » Usage
Reduced
complexity
everywhere
Decreased +
increased
stability
Software metrics » Observations
Refactoring
• Greatly reduced
“monster class”
• Split into multiple
reusable pieces
Software metrics » Usage
Questions?
Software metrics » Usage
OBSERVATIONS
Software metrics
Software metrics » Observations
Spikes!
Complexity often caused by a few commits!
Watch out with new features & rewrites.
Software metrics » Observations
Spikes!
Presentation titleSoftware metrics » Observations
Software metrics » Observations
No evolution
• No change over time
• No change across projects
Do developers have a “signature”?
Software metrics » Observations
No evolution
Software metrics » Observations
Personalities?
2 guys working on same project:
• One was very fast (but messier)
• One was a lot more thorough
Who’s who?
Software metrics » Observations
Personalities?
Software metrics » Observations
Personalities?
M
essy
Thorough
Software metrics » Observations
Personalities?
Can metrics show personality traits?
Please help me figure that out!
https://www.cauditor.org/user/feedback
Presentation title
Questions?
Software metrics
mullie.eu
• mullie.eu/measuring-software-complexity
• mullie.eu/measuring-software-coupling
• cauditor.org/help/metrics
Software metrics
Resources

More Related Content

PPT
Metrics
PDF
Chapter 6 software metrics
PPTX
Software Metrics - Software Engineering
PPTX
14 software technical_metrics
ODP
Software Measurement: Lecture 1. Measures and Metrics
PPTX
Software metrics
PPT
Software metrics
PDF
Software Metrics
Metrics
Chapter 6 software metrics
Software Metrics - Software Engineering
14 software technical_metrics
Software Measurement: Lecture 1. Measures and Metrics
Software metrics
Software metrics
Software Metrics

What's hot (20)

PPT
Software Metrics
PPT
Software Quality Metrics
PPT
Software process and project metrics
PDF
Software Engineering Practice - Software Metrics and Estimation
PPT
Sw quality metrics
PDF
PPTX
Product metrics
PPTX
Software engineering 13 software product metrics
PPTX
Estimation techniques and software metrics
PPT
Pressman ch-22-process-and-project-metrics
PPTX
Software Reliability
PPT
Chapter 15 software product metrics
PPT
Lecture3
PPTX
software metrics(process,project,product)
PPT
Software cost estimation
DOC
The importance of quality software
PPTX
Unit 8 software quality and matrices
PPT
Sop test planning
Software Metrics
Software Quality Metrics
Software process and project metrics
Software Engineering Practice - Software Metrics and Estimation
Sw quality metrics
Product metrics
Software engineering 13 software product metrics
Estimation techniques and software metrics
Pressman ch-22-process-and-project-metrics
Software Reliability
Chapter 15 software product metrics
Lecture3
software metrics(process,project,product)
Software cost estimation
The importance of quality software
Unit 8 software quality and matrices
Sop test planning
Ad

Viewers also liked (7)

PPTX
Software Metrics & Measurement-Sharbani Bhattacharya
PPT
Software metrics
PDF
Understanding software metrics
PPT
Sw Software Metrics
PPTX
Quality in software industry
PPT
Testing Metrics
Software Metrics & Measurement-Sharbani Bhattacharya
Software metrics
Understanding software metrics
Sw Software Metrics
Quality in software industry
Testing Metrics
Ad

Similar to Software metrics (20)

PDF
Measuring Your Code
PDF
Measuring Your Code 2.0
PDF
Measuring Your Code
PPTX
Software Quality Assessment Practices
PDF
Understanding, measuring and improving code quality in JavaScript
PPTX
OOAD - Ch.09 - Software Project Estimation.pptx
PPTX
Code metrics
PPTX
Code metrics
PDF
Writing Maintainable Code
PDF
Improving your CFML code quality
PPT
Software Product Measurement and Analysis in a Continuous Integration Environ...
PPT
2_metrics modified.ppt of software quality metrics
DOCX
Algorithm ExampleFor the following taskUse the random module .docx
PDF
Fuzzy Rule Base System for Software Classification
PDF
Software Metrics Course chapter 6 at Bahir Dar University
PDF
130924 yann-gael gueheneuc - an overview of software code quality and conne...
PDF
Code metrics in PHP
PPTX
Improving product usability with task complexity metrics
PDF
Dutch PHP Conference 2013: Distilled
DOC
Coupling based structural metrics for measuring the quality of a software (sy...
Measuring Your Code
Measuring Your Code 2.0
Measuring Your Code
Software Quality Assessment Practices
Understanding, measuring and improving code quality in JavaScript
OOAD - Ch.09 - Software Project Estimation.pptx
Code metrics
Code metrics
Writing Maintainable Code
Improving your CFML code quality
Software Product Measurement and Analysis in a Continuous Integration Environ...
2_metrics modified.ppt of software quality metrics
Algorithm ExampleFor the following taskUse the random module .docx
Fuzzy Rule Base System for Software Classification
Software Metrics Course chapter 6 at Bahir Dar University
130924 yann-gael gueheneuc - an overview of software code quality and conne...
Code metrics in PHP
Improving product usability with task complexity metrics
Dutch PHP Conference 2013: Distilled
Coupling based structural metrics for measuring the quality of a software (sy...

Recently uploaded (20)

PDF
AutoCAD Professional Crack 2025 With License Key
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
PPTX
Patient Appointment Booking in Odoo with online payment
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Autodesk AutoCAD Crack Free Download 2025
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Designing Intelligence for the Shop Floor.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Monitoring Stack: Grafana, Loki & Promtail
AutoCAD Professional Crack 2025 With License Key
Adobe Illustrator 28.6 Crack My Vision of Vector Design
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
Patient Appointment Booking in Odoo with online payment
wealthsignaloriginal-com-DS-text-... (1).pdf
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Oracle Fusion HCM Cloud Demo for Beginners
Autodesk AutoCAD Crack Free Download 2025
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Design an Analysis of Algorithms II-SECS-1021-03
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Designing Intelligence for the Shop Floor.pdf
CHAPTER 2 - PM Management and IT Context
Wondershare Filmora 15 Crack With Activation Key [2025
Monitoring Stack: Grafana, Loki & Promtail

Software metrics