Understanding
Software Metrics
Tushar Sharma
Tushar Sharma
Agenda
OO metrics
and their
classification
Using
metrics in
practice
Advanced
stuff…
Metrics:
What and
why
Software Metrics - What & Why?
A software metric is a measure of some property of a
software system.
Why?
“Measurement is the first step that leads to control and
eventually to improvement. If you can’t measure
something, you can’t understand it.”
(by James Harrington)
Tushar Sharma
Object-oriented Metrics
Size
Complexity
Cohesion &
Coupling
Project Namespace Type Method
LOC
NOC
NON
LOC
NOC
LOC
NOM
NOF
DIT
NC
RFC
LOC
NP
WMC CC
LCOM
CBO
Fan-in/
Fan-out
Tushar Sharma
OO Metrics - Size
• Large entities make the comprehension difficult.
• Large entities indicate presence of various smells.
LOC Lines Of Code
NON Number Of Namespaces
NOC Number Of Classes
NOM Number Of Methods
NOF Number Of Fields
Tushar Sharma
OO Metrics - Size
The response set of a class is a set
of methods that can potentially be
executed in response to a message
received by an object of that
class.
• Larger the number of methods that can be invoked, the greater the
complexity of the class.
• If a large number of methods can be invoked in response to a
message, the testing and debugging of the class becomes more
complicated .
RFC Response For Class
Tushar Sharma
OO Metrics - Size (Hierarchy)
• Deep inheritance trees make
the comprehension difficult.
• The deeper a class is in the
hierarchy, the greater the
number of methods it is likely
to inherit, making it more
complex to predict its
behaviour.
• Again, wide inheritance trees make the comprehension
difficult.
• A wide hierarchy indicates missing intermediate inheritance
level that in turn may lead to code duplication.
DIT Depth of Inheritance Tree
NC Number of Children
Tushar Sharma
OO Metrics - Cohesion and Coupling
Consider a class C with n methods M1, M2..., Mn. Let {Ij} = set of
instance variables used by method Mi.
There are n such sets I1 ,…, In
• P = {(Ii, Ij) | (Ii ∩ Ij ) = ∅}
• Q = {(Ii, Ij) | (Ii ∩ Ij ) ≠ ∅}
LCOM = |P| - |Q|, if |P| > |Q|
= 0, otherwise
• High LCOM indicate the violation of the Single Responsibility
Principle.
LCOM Lack of Cohesion
Of Methods
Tushar Sharma
OO Metrics - Cohesion and Coupling
CBO for a class is a
count of the number
of other classes to
which it is coupled.
• Excessive coupling between object classes is detrimental to
modular design and prevents reuse. The more independent a
class is, the easier it is to reuse it in another application.
• A measure of coupling is useful to determine how complex the
testing of various parts of a design are likely to be. The higher
the inter-object class coupling, the more rigorous the testing
needs to be.
CBO Coupling Between Object classes
Tushar Sharma
OO Metrics - Complexity
• CC - It is a quantitative measure of the number
of linearly independent paths through a
program's source code.
• WMC – Sum of CC of each method in the class
• The number of methods and the complexity of methods involved
is a predictor of how much time and effort is required to develop
and maintain the class.
CC Cyclomatic Complexity
WMC Weighted Methods per Class
Tushar Sharma
Using metrics in practice - tools
C/C++
CppDepend
Infusion
Source Monitor
C#
Designite
NDepend
Java
Infusion
Source Monitor
Tushar Sharma
Using metrics in practice
• There is no one single widely accepted standard for metrics
thresholds.
• There are some guidelines and rules of thumb!
Metric - Recommended Threshold
LOC (Method) - 50
LOC (File) - 500
NOC - 9
DIT - 5
LCOM - 0.80
NOM - 30
CBO - 6
CC - 10
WMC - 100
% Duplication - 4%
Metric thresholds
Tushar Sharma
Using metrics in practice
What if you want to perform an analysis with customized metric
thresholds
http://www.designite-tools.com
Tushar Sharma
What can be done with metrics data
• Indicator of “Structural Quality”
• Refactoring candidates
LackofCohesion
0
500
1000
1500
2000
2500
3000
3500
createFaxFaxSender
PrintSender
SASC
ontext
SASFoldableTableC
ellW
idget
SASFoldableTable
SASSortFoldableTable
SASFoldableD
ynam
icC
olum
nScrollTable
SASFoldableD
ynam
icTable
SASSortTable
SASLaterality
SASProcedureTree
SASSiriusLPA
SASProcedureTreeU
serO
bject
PortalApplication
PortalR
ISApplicationR
adiologist
SASServerH
essianProxy
C
lientC
onfig
U
serPreferences
SASC
riteria
SASSpeechTextPaneD
ispatcher
SpeechAudioU
tils
Classes
Lackofcohesionvalue
0 120 180
Threshold
• Trend analysis
• Proof – Improved quality
Tushar Sharma
What can be done with metrics data
• Detect code/design smells:
✦ Insufficient Modularization - WMC or NOM
✦ Hub-like Modularization – Fan-in/Fan-out
✦ Deep Hierarchy – DIT
✦ Multifaceted Abstraction – LCOM
✦ …
Some more metrics
❖ Mood (Metrics for Object-Oriented Design)
✦ Method Hiding Factor (MHF)
✦ ratio of sum of the invisibilities of all methods defined in all
classes to the total number of methods
✦ Attribute Hiding Factor (AHF)
✦ Method Inheritance Factor (MIF)
✦ ratio of the sum of the inherited methods in all classes to the
total number of available methods (locally defined plus
inherited) for all classes
✦ Attribute Inheritance Factor (AIF)
✦ …
Tushar Sharma
Abstractness Vs Instability
• Dependency
• say class Copy depends on KeyboardReader
• “Good dependency”?
• where target of the dependency is stable
• stable - does not depend on anything, not going to change
• Responsible class
• many classes depend on the class
• it’s harder to change
• and therefore, must be stable
Tushar Sharma
• Instability
• Ca - Afferent coupling (Fan-in)
• Ce - Efferent coupling (Fan-out)
Abstractness Vs Instability
• So, shouldn’t we have all classes as stable classes?
• No. System will be unchangeable.
• Therefore, we need some portion of the design to be flexible to
withstand change.
• How? Abstract classes
• Abstractness = #abstract classes / #total classes in the group
Tushar Sharma
Abstractness Vs Instability
(1, 0) - Max
instable and
concrete
(0, 0) - Max
stable and
concrete
(0.5, 0.5) -
striking the
balance
(0, 1) - Max
stable and
abstract
Zone of pain
Zone of uselessness
M
ain
sequence
Abstractness
Instability
(1, 1) - abstract
and max
instable (no
dependents)
Tushar Sharma
Let’s conclude!!
Strive quality not numbers.
Thank you
for your attention.
tusharsharma@ieee.org

More Related Content

PPTX
DevOps introduction
PPTX
GCP.pptx
PDF
The What, Why, and How of DevSecOps
PPTX
Introduction to Google Cloud Platform
PPTX
DevOps 101 - an Introduction to DevOps
PPTX
DevSecOps reference architectures 2018
PDF
Netflix Global Cloud Architecture
PDF
Robot Framework with Python | Edureka
DevOps introduction
GCP.pptx
The What, Why, and How of DevSecOps
Introduction to Google Cloud Platform
DevOps 101 - an Introduction to DevOps
DevSecOps reference architectures 2018
Netflix Global Cloud Architecture
Robot Framework with Python | Edureka

What's hot (20)

PDF
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
PPTX
Google Cloud Platform (GCP)
PDF
DevOps vs. Site Reliability Engineering (SRE) in Age of Kubernetes
PDF
Walking Through Spring Cloud Data Flow
PPTX
Scaling production grade EKS Multi-Cluster environments using GitOps
PDF
API Management within a Microservice Architecture
PPTX
Integrating Public & Private Clouds
PPTX
AWS Lambda Tutorial For Beginners | What is AWS Lambda? | AWS Tutorial For Be...
PPTX
SDLC ITS MODEL AND SOFTWARE TESTING
PPTX
API Integration: Red Hat integration perspective
PDF
Aws Architecture Fundamentals
PDF
Serverless computing with AWS Lambda
PDF
Build the right culture in DevSecOps
PPTX
Product metrics
PDF
Boost your AWS Infrastructure with CDK
PDF
Google cloud platform introduction
PPTX
Terraform Basics
PDF
Introduction to DevOps
PDF
Model-Based Testing: Why, What, How
PPTX
Madrid meetup #7 deployment models
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
Google Cloud Platform (GCP)
DevOps vs. Site Reliability Engineering (SRE) in Age of Kubernetes
Walking Through Spring Cloud Data Flow
Scaling production grade EKS Multi-Cluster environments using GitOps
API Management within a Microservice Architecture
Integrating Public & Private Clouds
AWS Lambda Tutorial For Beginners | What is AWS Lambda? | AWS Tutorial For Be...
SDLC ITS MODEL AND SOFTWARE TESTING
API Integration: Red Hat integration perspective
Aws Architecture Fundamentals
Serverless computing with AWS Lambda
Build the right culture in DevSecOps
Product metrics
Boost your AWS Infrastructure with CDK
Google cloud platform introduction
Terraform Basics
Introduction to DevOps
Model-Based Testing: Why, What, How
Madrid meetup #7 deployment models
Ad

Viewers also liked (20)

PDF
Technical debt - The elephant in the room
PDF
Tools for Identifying and Addressing Technical Debt
PPT
Software metrics
PPT
Sw Software Metrics
PPTX
Software Metrics & Measurement-Sharbani Bhattacharya
PDF
Software metrics
PPT
Software Metrics
PDF
Software metrics
PPTX
Software metrics
PPTX
Measurement Metrics for Object Oriented Design
PDF
Software quality metric
PPTX
Software quality metrics methodology _tanmi kiran
PPT
A Validation of Object-Oriented Design Metrics as Quality Indicators
PPT
Software Engineering Fundamentals
PDF
Software Engineering Practice - Software Metrics and Estimation
PDF
Object-Oriented Metrics in Practice
PPT
Software metrics
PPTX
Software Metrics - Software Engineering
PDF
Importance of software quality metrics
PPTX
Quality in software industry
Technical debt - The elephant in the room
Tools for Identifying and Addressing Technical Debt
Software metrics
Sw Software Metrics
Software Metrics & Measurement-Sharbani Bhattacharya
Software metrics
Software Metrics
Software metrics
Software metrics
Measurement Metrics for Object Oriented Design
Software quality metric
Software quality metrics methodology _tanmi kiran
A Validation of Object-Oriented Design Metrics as Quality Indicators
Software Engineering Fundamentals
Software Engineering Practice - Software Metrics and Estimation
Object-Oriented Metrics in Practice
Software metrics
Software Metrics - Software Engineering
Importance of software quality metrics
Quality in software industry
Ad

Similar to Understanding software metrics (20)

PPTX
Feature Selection Techniques for Software Fault Prediction (Summary)
PPTX
Improving Search Relevance in Elasticsearch Using Machine Learning - Milorad ...
PPTX
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
PDF
Lecture 3 Requirements and Quality Attributes 16 Sept 2020.pdf
PDF
Presentation by Lionel Briand
DOCX
Algorithm ExampleFor the following taskUse the random module .docx
PPTX
Lesson5-Algorithms-Flowcharts-DataTypes-Pseudocode.pptx
PDF
Crowdsourced query augmentation through the semantic discovery of domain spec...
PPTX
An Empirical Study on the Adequacy of Testing in Open Source Projects
PPTX
The Impact of Test Ownership and Team Structure on the Reliability and Effect...
PPT
PPT
N depend & cql
PPT
B2 2005 introduction_load_testing_blackboard_primer_draft
PPT
Sfeldman performance bb_worldemea07
PPT
12 functional-system-testing
PPTX
Infosys Interview Questions And Answers 2023
PPT
NDepend Public PPT (2008)
PDF
What are the Unique Challenges and Opportunities in Systems for ML?
PPTX
Keynote at IWLS 2017
Feature Selection Techniques for Software Fault Prediction (Summary)
Improving Search Relevance in Elasticsearch Using Machine Learning - Milorad ...
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
Lecture 3 Requirements and Quality Attributes 16 Sept 2020.pdf
Presentation by Lionel Briand
Algorithm ExampleFor the following taskUse the random module .docx
Lesson5-Algorithms-Flowcharts-DataTypes-Pseudocode.pptx
Crowdsourced query augmentation through the semantic discovery of domain spec...
An Empirical Study on the Adequacy of Testing in Open Source Projects
The Impact of Test Ownership and Team Structure on the Reliability and Effect...
N depend & cql
B2 2005 introduction_load_testing_blackboard_primer_draft
Sfeldman performance bb_worldemea07
12 functional-system-testing
Infosys Interview Questions And Answers 2023
NDepend Public PPT (2008)
What are the Unique Challenges and Opportunities in Systems for ML?
Keynote at IWLS 2017

More from Tushar Sharma (20)

PDF
House of Cards: Code Smells in Open-source C# Repositories
PDF
The tail of two source-code analysis tools - Learning and experiences
PDF
Designite: A Customizable Tool for Smell Mining in C# Repositories
PDF
Writing Maintainable Code
PDF
FOSDEM - Does your configuration code smell?
PDF
Achieving Design Agility by Refactoring Design Smells
PDF
Does your configuration code smell?
PDF
Designite – Software Design Quality Assessment Tool
PDF
Does Your Configuration Code Smell?
PDF
Pragmatic Technical Debt Management
PDF
Infographic - Pragmatic Technical Debt Management
PDF
Applying Design Principles in Practice
PDF
Why care about technical debt?
PDF
Does your design smell?
PDF
A Checklist for Design Reviews
PDF
Tools for refactoring
PDF
Towards a Principle-based Classification of Structural Design Smells
PDF
PHAME: Principles of Hierarchy Abstraction Modularization and Encapsulation
PDF
Refactoring for Design Smells - ICSE 2014 Tutorial
PDF
Refactoring for Software Design Smells: Managing Technical Debt
House of Cards: Code Smells in Open-source C# Repositories
The tail of two source-code analysis tools - Learning and experiences
Designite: A Customizable Tool for Smell Mining in C# Repositories
Writing Maintainable Code
FOSDEM - Does your configuration code smell?
Achieving Design Agility by Refactoring Design Smells
Does your configuration code smell?
Designite – Software Design Quality Assessment Tool
Does Your Configuration Code Smell?
Pragmatic Technical Debt Management
Infographic - Pragmatic Technical Debt Management
Applying Design Principles in Practice
Why care about technical debt?
Does your design smell?
A Checklist for Design Reviews
Tools for refactoring
Towards a Principle-based Classification of Structural Design Smells
PHAME: Principles of Hierarchy Abstraction Modularization and Encapsulation
Refactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Software Design Smells: Managing Technical Debt

Recently uploaded (20)

PDF
NU-MEP-Standards معايير تصميم جامعية .pdf
PPTX
Chapter security of computer_8_v8.1.pptx
PPTX
Power BI - Microsoft Power BI is an interactive data visualization software p...
PDF
9 FinOps Tools That Simplify Cloud Cost Reporting.pdf
PDF
Mcdonald's : a half century growth . pdf
PPTX
Overview_of_Computing_Presentation.pptxxx
PPTX
Bussiness Plan S Group of college 2020-23 Final
PDF
Nucleic-Acids_-Structure-Typ...-1.pdf 011
PDF
American Journal of Multidisciplinary Research and Review
PPT
Technicalities in writing workshops indigenous language
PDF
Introduction to Database Systems Lec # 1
PPTX
PPT for Diseases (1)-2, types of diseases.pptx
PPTX
Capstone Presentation a.pptx on data sci
PDF
book-34714 (2).pdfhjkkljgfdssawtjiiiiiujj
PPTX
ISO 9001-2015 quality management system presentation
PPTX
DAA UNIT 1 for unit 1 time compixity PPT.pptx
PDF
PPT nikita containers of the company use
PDF
Hikvision-IR-PPT---EN.pdfSADASDASSAAAAAAAAAAAAAAA
PPTX
DATA ANALYTICS COURSE IN PITAMPURA.pptx
PDF
Teal Blue Futuristic Metaverse Presentation.pdf
NU-MEP-Standards معايير تصميم جامعية .pdf
Chapter security of computer_8_v8.1.pptx
Power BI - Microsoft Power BI is an interactive data visualization software p...
9 FinOps Tools That Simplify Cloud Cost Reporting.pdf
Mcdonald's : a half century growth . pdf
Overview_of_Computing_Presentation.pptxxx
Bussiness Plan S Group of college 2020-23 Final
Nucleic-Acids_-Structure-Typ...-1.pdf 011
American Journal of Multidisciplinary Research and Review
Technicalities in writing workshops indigenous language
Introduction to Database Systems Lec # 1
PPT for Diseases (1)-2, types of diseases.pptx
Capstone Presentation a.pptx on data sci
book-34714 (2).pdfhjkkljgfdssawtjiiiiiujj
ISO 9001-2015 quality management system presentation
DAA UNIT 1 for unit 1 time compixity PPT.pptx
PPT nikita containers of the company use
Hikvision-IR-PPT---EN.pdfSADASDASSAAAAAAAAAAAAAAA
DATA ANALYTICS COURSE IN PITAMPURA.pptx
Teal Blue Futuristic Metaverse Presentation.pdf

Understanding software metrics

  • 2. Tushar Sharma Agenda OO metrics and their classification Using metrics in practice Advanced stuff… Metrics: What and why
  • 3. Software Metrics - What & Why? A software metric is a measure of some property of a software system. Why? “Measurement is the first step that leads to control and eventually to improvement. If you can’t measure something, you can’t understand it.” (by James Harrington)
  • 4. Tushar Sharma Object-oriented Metrics Size Complexity Cohesion & Coupling Project Namespace Type Method LOC NOC NON LOC NOC LOC NOM NOF DIT NC RFC LOC NP WMC CC LCOM CBO Fan-in/ Fan-out
  • 5. Tushar Sharma OO Metrics - Size • Large entities make the comprehension difficult. • Large entities indicate presence of various smells. LOC Lines Of Code NON Number Of Namespaces NOC Number Of Classes NOM Number Of Methods NOF Number Of Fields
  • 6. Tushar Sharma OO Metrics - Size The response set of a class is a set of methods that can potentially be executed in response to a message received by an object of that class. • Larger the number of methods that can be invoked, the greater the complexity of the class. • If a large number of methods can be invoked in response to a message, the testing and debugging of the class becomes more complicated . RFC Response For Class
  • 7. Tushar Sharma OO Metrics - Size (Hierarchy) • Deep inheritance trees make the comprehension difficult. • The deeper a class is in the hierarchy, the greater the number of methods it is likely to inherit, making it more complex to predict its behaviour. • Again, wide inheritance trees make the comprehension difficult. • A wide hierarchy indicates missing intermediate inheritance level that in turn may lead to code duplication. DIT Depth of Inheritance Tree NC Number of Children
  • 8. Tushar Sharma OO Metrics - Cohesion and Coupling Consider a class C with n methods M1, M2..., Mn. Let {Ij} = set of instance variables used by method Mi. There are n such sets I1 ,…, In • P = {(Ii, Ij) | (Ii ∩ Ij ) = ∅} • Q = {(Ii, Ij) | (Ii ∩ Ij ) ≠ ∅} LCOM = |P| - |Q|, if |P| > |Q| = 0, otherwise • High LCOM indicate the violation of the Single Responsibility Principle. LCOM Lack of Cohesion Of Methods
  • 9. Tushar Sharma OO Metrics - Cohesion and Coupling CBO for a class is a count of the number of other classes to which it is coupled. • Excessive coupling between object classes is detrimental to modular design and prevents reuse. The more independent a class is, the easier it is to reuse it in another application. • A measure of coupling is useful to determine how complex the testing of various parts of a design are likely to be. The higher the inter-object class coupling, the more rigorous the testing needs to be. CBO Coupling Between Object classes
  • 10. Tushar Sharma OO Metrics - Complexity • CC - It is a quantitative measure of the number of linearly independent paths through a program's source code. • WMC – Sum of CC of each method in the class • The number of methods and the complexity of methods involved is a predictor of how much time and effort is required to develop and maintain the class. CC Cyclomatic Complexity WMC Weighted Methods per Class
  • 11. Tushar Sharma Using metrics in practice - tools C/C++ CppDepend Infusion Source Monitor C# Designite NDepend Java Infusion Source Monitor
  • 12. Tushar Sharma Using metrics in practice • There is no one single widely accepted standard for metrics thresholds. • There are some guidelines and rules of thumb! Metric - Recommended Threshold LOC (Method) - 50 LOC (File) - 500 NOC - 9 DIT - 5 LCOM - 0.80 NOM - 30 CBO - 6 CC - 10 WMC - 100 % Duplication - 4% Metric thresholds
  • 13. Tushar Sharma Using metrics in practice What if you want to perform an analysis with customized metric thresholds http://www.designite-tools.com
  • 14. Tushar Sharma What can be done with metrics data • Indicator of “Structural Quality” • Refactoring candidates LackofCohesion 0 500 1000 1500 2000 2500 3000 3500 createFaxFaxSender PrintSender SASC ontext SASFoldableTableC ellW idget SASFoldableTable SASSortFoldableTable SASFoldableD ynam icC olum nScrollTable SASFoldableD ynam icTable SASSortTable SASLaterality SASProcedureTree SASSiriusLPA SASProcedureTreeU serO bject PortalApplication PortalR ISApplicationR adiologist SASServerH essianProxy C lientC onfig U serPreferences SASC riteria SASSpeechTextPaneD ispatcher SpeechAudioU tils Classes Lackofcohesionvalue 0 120 180 Threshold • Trend analysis • Proof – Improved quality
  • 15. Tushar Sharma What can be done with metrics data • Detect code/design smells: ✦ Insufficient Modularization - WMC or NOM ✦ Hub-like Modularization – Fan-in/Fan-out ✦ Deep Hierarchy – DIT ✦ Multifaceted Abstraction – LCOM ✦ …
  • 16. Some more metrics ❖ Mood (Metrics for Object-Oriented Design) ✦ Method Hiding Factor (MHF) ✦ ratio of sum of the invisibilities of all methods defined in all classes to the total number of methods ✦ Attribute Hiding Factor (AHF) ✦ Method Inheritance Factor (MIF) ✦ ratio of the sum of the inherited methods in all classes to the total number of available methods (locally defined plus inherited) for all classes ✦ Attribute Inheritance Factor (AIF) ✦ …
  • 17. Tushar Sharma Abstractness Vs Instability • Dependency • say class Copy depends on KeyboardReader • “Good dependency”? • where target of the dependency is stable • stable - does not depend on anything, not going to change • Responsible class • many classes depend on the class • it’s harder to change • and therefore, must be stable
  • 18. Tushar Sharma • Instability • Ca - Afferent coupling (Fan-in) • Ce - Efferent coupling (Fan-out) Abstractness Vs Instability • So, shouldn’t we have all classes as stable classes? • No. System will be unchangeable. • Therefore, we need some portion of the design to be flexible to withstand change. • How? Abstract classes • Abstractness = #abstract classes / #total classes in the group
  • 19. Tushar Sharma Abstractness Vs Instability (1, 0) - Max instable and concrete (0, 0) - Max stable and concrete (0.5, 0.5) - striking the balance (0, 1) - Max stable and abstract Zone of pain Zone of uselessness M ain sequence Abstractness Instability (1, 1) - abstract and max instable (no dependents)