SlideShare a Scribd company logo
1 of 18
CODE METRICS
Eng. Mohammad R. Katby
Which line of code easier to understand?
int x = x + 1;
int x = y + 1;
or
CODE METRICS Eng. Mohammad R. Katby
Agenda
■ What are the code measurement units?
■ What we are going to measure?
■ Why we need code metrics
■ What are code metrics
What are Code Metrics
■ Length
■ Vocabulary
■ Difficulty
■ Volume
■ Effort
■ Bugs
■ Structuredness
■ Complexity
■ Maintainability
■ Independability
Why we need measurements?
■ Without measurement you cannot understand code faults
■ See whether improvement can be made or not
■ Simply you can’t be Electrician if you can’t measure the voltage
Pioneers of Code Metrics
Thomas J. McCabe - 1976 Maurice Halstead - 1977
int x = x + 1;
Operators
Operands
Operand: 4, Unique: 3
Operator: 3, Unique: 3
OD = 4; UOD = 3
OP = 3; UOP = 3
Halstead metrics “Primitives”
■ Length (LTH) = OP + OD = 3 + 4 = 7
■ Vocabulary (VOC) = UOP + UOD = 3 + 3 = 6
■ Difficulty (DIF) = (UOP / 2) * (OD / UOD) = (3 / 2) * (4 / 3) = 1.99
■ OP = 3, UOP = 3, OD = 4, UOD = 4
■ LTH = 3 + 4 = 7
■ VOC = 3 + 4 = 7
■ DIF = (3 / 2) * (4 / 4) = 1.5
int x = x + 1;
int x = y + 1;
Halstead metrics “Derived”
■ Volume (VOL) = LTH * Log2(VOC) = 7 * 2.58 = 18.06
– You can view this as the ‘bulk’ of the code
– how much information does the reader of the code have to absorb to understand
its meaning
– biggest influence on theVolume metric is the Halstead length
Halstead metrics “Derived”
■ Bugs (BUG) =VOL / 3000 = 18.06 / 3000
– Estimates how many bugs you are likely to find in the system.
Halstead metrics “Derived”
■ Effort (EFF) = DIF *VOL = 1.99 * 18.06 = 38.96 / 18 = 2.16 (sec)
– The amount of mental effort required to recreate the software
Cyclomatic Complexity
■ Counting the number of decisions made in our source code.
■ Determine number test cases that need to be written
■ there is no exact limit that fits all organizations. However, a limit
of 10 is a good for such our industry
■ Measure: Strcuturedness, Complexity
Class Coupling
■ Measure how many classes a single class uses
■ Has been shown to be an accurate predictor of software failure
■ High coupling indicates design that is difficult to reuse and maintain
■ There is no limit that fits all organizations. However, a limit of 9 is optimal
■ Measure: Reusability, Maintainability,Changeability
Depth of Inheritance
■ The maximum length from the node to the root of the tree
■ Harder to predict behavior
■ Increase complexity of design since more classes and methods are involved
■ Have a greater potential for reusing
■ Several researches suggest that a DIT around 5 or 6 should be an upper limit
Maintainability Index
■ High value means better maintainability.
– LOW - red rating is a rating between 0 and 9
– MODERIATE - yellow rating is between 10 and 19
– GOOD - green rating is between 20 and 100
■ Maintainability Index = MAX(0,(171 – 5.2 * log(HalsteadVolume) – 0.23 * (Cyclomatic
Complexity) – 16.2 * log(Lines of Code))*100 / 171)
■
Levels of Measurement
■ Method
■ Class
■ Package and system
References
■ http://moosehead.cis.umassd.edu/cis580/readings/OO_Design_Complexity_Metrics.p
df
■ http://www.mccabe.com/pdf/mccabe-nist235r.pdf
■ http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.104.4041&rep=rep1&type=
pdf
■ http://www.campwoodsw.com/sourcemonitor.html
■ https://sourceforge.net/projects/metrics/

More Related Content

What's hot

Software testing methods, levels and types
Software testing methods, levels and typesSoftware testing methods, levels and types
Software testing methods, levels and types
Confiz
 
Basic software-testing-concepts
Basic software-testing-conceptsBasic software-testing-concepts
Basic software-testing-concepts
medsherb
 
Software quality assurance
Software quality assuranceSoftware quality assurance
Software quality assurance
Er. Nancy
 

What's hot (20)

Testing fundamentals
Testing fundamentalsTesting fundamentals
Testing fundamentals
 
Software Reliability
Software ReliabilitySoftware Reliability
Software Reliability
 
Software Metrics
Software MetricsSoftware Metrics
Software Metrics
 
Software Testing Introduction
Software Testing IntroductionSoftware Testing Introduction
Software Testing Introduction
 
Software testing
Software testingSoftware testing
Software testing
 
Software testing methods, levels and types
Software testing methods, levels and typesSoftware testing methods, levels and types
Software testing methods, levels and types
 
Software metrics
Software metricsSoftware metrics
Software metrics
 
Introducing DevOps
Introducing DevOpsIntroducing DevOps
Introducing DevOps
 
Basic software-testing-concepts
Basic software-testing-conceptsBasic software-testing-concepts
Basic software-testing-concepts
 
Se (techniques for black box testing ppt)
Se (techniques for black box testing ppt)Se (techniques for black box testing ppt)
Se (techniques for black box testing ppt)
 
IT8076 - SOFTWARE TESTING
IT8076 - SOFTWARE TESTINGIT8076 - SOFTWARE TESTING
IT8076 - SOFTWARE TESTING
 
Software quality assurance
Software quality assuranceSoftware quality assurance
Software quality assurance
 
Software quality assurance
Software quality assuranceSoftware quality assurance
Software quality assurance
 
What is the psychology of testing
What is the psychology of testingWhat is the psychology of testing
What is the psychology of testing
 
Software testing
Software testingSoftware testing
Software testing
 
Code coverage
Code coverageCode coverage
Code coverage
 
Software testing performance testing
Software testing  performance testingSoftware testing  performance testing
Software testing performance testing
 
Software testing
Software testing Software testing
Software testing
 
Introduction & Manual Testing
Introduction & Manual TestingIntroduction & Manual Testing
Introduction & Manual Testing
 
Software engineering 23 software reliability
Software engineering 23 software reliabilitySoftware engineering 23 software reliability
Software engineering 23 software reliability
 

Viewers also liked

Viewers also liked (6)

Object oriented design
Object oriented designObject oriented design
Object oriented design
 
Decorator pattern
Decorator patternDecorator pattern
Decorator pattern
 
Principal 4 Enabling A Holistic Approach
Principal 4 Enabling A Holistic ApproachPrincipal 4 Enabling A Holistic Approach
Principal 4 Enabling A Holistic Approach
 
COBIT5 Implementation Guidance
COBIT5 Implementation GuidanceCOBIT5 Implementation Guidance
COBIT5 Implementation Guidance
 
What is Cobit
What is CobitWhat is Cobit
What is Cobit
 
Geospatial analytics data science sg meetup
Geospatial analytics   data science sg meetupGeospatial analytics   data science sg meetup
Geospatial analytics data science sg meetup
 

Similar to Code metrics

Design and Analysis Algorithms.pdf
Design and Analysis Algorithms.pdfDesign and Analysis Algorithms.pdf
Design and Analysis Algorithms.pdf
HarshNagda5
 

Similar to Code metrics (20)

01 intro to algorithm--updated 2015
01 intro to algorithm--updated 201501 intro to algorithm--updated 2015
01 intro to algorithm--updated 2015
 
Design and Analysis Algorithms.pdf
Design and Analysis Algorithms.pdfDesign and Analysis Algorithms.pdf
Design and Analysis Algorithms.pdf
 
Design and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit oneDesign and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit one
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
 
Introduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.pptIntroduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.ppt
 
04 performance
04 performance04 performance
04 performance
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structure
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptx
 
Searching Algorithms
Searching AlgorithmsSearching Algorithms
Searching Algorithms
 
Lect1.pptx
Lect1.pptxLect1.pptx
Lect1.pptx
 
Algorithms.pdf
Algorithms.pdfAlgorithms.pdf
Algorithms.pdf
 
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.pptBCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
 
DATA STRUCTURE.pdf
DATA STRUCTURE.pdfDATA STRUCTURE.pdf
DATA STRUCTURE.pdf
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
 
Python algorithm
Python algorithmPython algorithm
Python algorithm
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & Algorithms
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
 
Unit no_1.pptx
Unit no_1.pptxUnit no_1.pptx
Unit no_1.pptx
 

More from Mohammad Reda Katby

More from Mohammad Reda Katby (7)

Global Artificial Intelligence (AI) Index
Global Artificial Intelligence (AI) IndexGlobal Artificial Intelligence (AI) Index
Global Artificial Intelligence (AI) Index
 
Code metrics
Code metricsCode metrics
Code metrics
 
COBIT 5 - Principal 5 Separating Governance From Management
COBIT 5 - Principal 5 Separating Governance From ManagementCOBIT 5 - Principal 5 Separating Governance From Management
COBIT 5 - Principal 5 Separating Governance From Management
 
COBIT 5 - Principal 3 Applying A Single Integrated Framework
COBIT 5 - Principal 3 Applying A Single Integrated FrameworkCOBIT 5 - Principal 3 Applying A Single Integrated Framework
COBIT 5 - Principal 3 Applying A Single Integrated Framework
 
COBIT 5 Principal 2 Covering the Enterprise End-To-End
COBIT 5 Principal 2 Covering the Enterprise End-To-EndCOBIT 5 Principal 2 Covering the Enterprise End-To-End
COBIT 5 Principal 2 Covering the Enterprise End-To-End
 
Cobit5 Principal 1 Meeting Stakeholder Needs
Cobit5 Principal 1 Meeting Stakeholder NeedsCobit5 Principal 1 Meeting Stakeholder Needs
Cobit5 Principal 1 Meeting Stakeholder Needs
 
COBIT5 Introduction
COBIT5 IntroductionCOBIT5 Introduction
COBIT5 Introduction
 

Recently uploaded

Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
JoseMangaJr1
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
AroojKhan71
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
amitlee9823
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
amitlee9823
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
MarinCaroMartnezBerg
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 

Recently uploaded (20)

ELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptxELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptx
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 

Code metrics

  • 2. Which line of code easier to understand? int x = x + 1; int x = y + 1; or CODE METRICS Eng. Mohammad R. Katby
  • 3. Agenda ■ What are the code measurement units? ■ What we are going to measure? ■ Why we need code metrics ■ What are code metrics
  • 4.
  • 5. What are Code Metrics ■ Length ■ Vocabulary ■ Difficulty ■ Volume ■ Effort ■ Bugs ■ Structuredness ■ Complexity ■ Maintainability ■ Independability
  • 6. Why we need measurements? ■ Without measurement you cannot understand code faults ■ See whether improvement can be made or not ■ Simply you can’t be Electrician if you can’t measure the voltage
  • 7. Pioneers of Code Metrics Thomas J. McCabe - 1976 Maurice Halstead - 1977
  • 8. int x = x + 1; Operators Operands Operand: 4, Unique: 3 Operator: 3, Unique: 3 OD = 4; UOD = 3 OP = 3; UOP = 3
  • 9. Halstead metrics “Primitives” ■ Length (LTH) = OP + OD = 3 + 4 = 7 ■ Vocabulary (VOC) = UOP + UOD = 3 + 3 = 6 ■ Difficulty (DIF) = (UOP / 2) * (OD / UOD) = (3 / 2) * (4 / 3) = 1.99 ■ OP = 3, UOP = 3, OD = 4, UOD = 4 ■ LTH = 3 + 4 = 7 ■ VOC = 3 + 4 = 7 ■ DIF = (3 / 2) * (4 / 4) = 1.5 int x = x + 1; int x = y + 1;
  • 10. Halstead metrics “Derived” ■ Volume (VOL) = LTH * Log2(VOC) = 7 * 2.58 = 18.06 – You can view this as the ‘bulk’ of the code – how much information does the reader of the code have to absorb to understand its meaning – biggest influence on theVolume metric is the Halstead length
  • 11. Halstead metrics “Derived” ■ Bugs (BUG) =VOL / 3000 = 18.06 / 3000 – Estimates how many bugs you are likely to find in the system.
  • 12. Halstead metrics “Derived” ■ Effort (EFF) = DIF *VOL = 1.99 * 18.06 = 38.96 / 18 = 2.16 (sec) – The amount of mental effort required to recreate the software
  • 13. Cyclomatic Complexity ■ Counting the number of decisions made in our source code. ■ Determine number test cases that need to be written ■ there is no exact limit that fits all organizations. However, a limit of 10 is a good for such our industry ■ Measure: Strcuturedness, Complexity
  • 14. Class Coupling ■ Measure how many classes a single class uses ■ Has been shown to be an accurate predictor of software failure ■ High coupling indicates design that is difficult to reuse and maintain ■ There is no limit that fits all organizations. However, a limit of 9 is optimal ■ Measure: Reusability, Maintainability,Changeability
  • 15. Depth of Inheritance ■ The maximum length from the node to the root of the tree ■ Harder to predict behavior ■ Increase complexity of design since more classes and methods are involved ■ Have a greater potential for reusing ■ Several researches suggest that a DIT around 5 or 6 should be an upper limit
  • 16. Maintainability Index ■ High value means better maintainability. – LOW - red rating is a rating between 0 and 9 – MODERIATE - yellow rating is between 10 and 19 – GOOD - green rating is between 20 and 100 ■ Maintainability Index = MAX(0,(171 – 5.2 * log(HalsteadVolume) – 0.23 * (Cyclomatic Complexity) – 16.2 * log(Lines of Code))*100 / 171) ■
  • 17. Levels of Measurement ■ Method ■ Class ■ Package and system
  • 18. References ■ http://moosehead.cis.umassd.edu/cis580/readings/OO_Design_Complexity_Metrics.p df ■ http://www.mccabe.com/pdf/mccabe-nist235r.pdf ■ http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.104.4041&rep=rep1&type= pdf ■ http://www.campwoodsw.com/sourcemonitor.html ■ https://sourceforge.net/projects/metrics/