SlideShare a Scribd company logo
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
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

PDF
Linux directory structure by jitu mistry
PDF
Ceph Day Beijing - SPDK for Ceph
PPTX
Linux device drivers
PPT
Introduction to System Calls
PDF
Embedded Linux Kernel - Build your custom kernel
PDF
Course 102: Lecture 22: Package Management
PDF
Issues in the design of Code Generator
Linux directory structure by jitu mistry
Ceph Day Beijing - SPDK for Ceph
Linux device drivers
Introduction to System Calls
Embedded Linux Kernel - Build your custom kernel
Course 102: Lecture 22: Package Management
Issues in the design of Code Generator

What's hot (20)

PPT
Linux command ppt
PDF
Linux-Internals-and-Networking
PDF
File systems for Embedded Linux
PDF
PDF
Linux scheduler
PDF
Linux kernel modules
PDF
Kernel Module Programming
PPTX
The Next Linux Superpower: eBPF Primer
PDF
Android OTA updates
PDF
Linux Internals - Part II
PDF
Part 02 Linux Kernel Module Programming
PDF
Faster packet processing in Linux: XDP
PDF
Embedded Operating System - Linux
PDF
Performance Analysis Tools for Linux Kernel
PDF
Bootloaders
ODP
Basics of boot-loader
PDF
Linux Kernel - Virtual File System
PPTX
The TCP/IP Stack in the Linux Kernel
PPT
Kernel module programming
PPTX
Kernel module in linux os.
Linux command ppt
Linux-Internals-and-Networking
File systems for Embedded Linux
Linux scheduler
Linux kernel modules
Kernel Module Programming
The Next Linux Superpower: eBPF Primer
Android OTA updates
Linux Internals - Part II
Part 02 Linux Kernel Module Programming
Faster packet processing in Linux: XDP
Embedded Operating System - Linux
Performance Analysis Tools for Linux Kernel
Bootloaders
Basics of boot-loader
Linux Kernel - Virtual File System
The TCP/IP Stack in the Linux Kernel
Kernel module programming
Kernel module in linux os.
Ad

Viewers also liked (6)

PPTX
Object oriented design
PPTX
Decorator pattern
PPTX
Principal 4 Enabling A Holistic Approach
PPTX
COBIT5 Implementation Guidance
PDF
What is Cobit
PDF
Geospatial analytics data science sg meetup
Object oriented design
Decorator pattern
Principal 4 Enabling A Holistic Approach
COBIT5 Implementation Guidance
What is Cobit
Geospatial analytics data science sg meetup
Ad

Similar to Code metrics (20)

PPTX
Unit3_Software-MDFJHGFUGJFSJDFMHGSAD,MFKJASDFH,ADSFGAKSIF,AWKJEHGF,Aetrics.pptx
PPTX
source code metrics and other maintenance tools and techniques
DOCX
Algorithm ExampleFor the following taskUse the random module .docx
PPT
Software metrics
PDF
Software metrics
PPTX
software engineering module i & ii.pptx
PDF
Sw metrics for regression testing
PPTX
A New Reusability Metric for Object-Oriented Software
PPSX
Software Metrics
ODP
Software Measurement: Lecture 1. Measures and Metrics
PDF
Software Metrics Course chapter 6 at Bahir Dar University
PPTX
Software engineering module 4 notes for btech and mca
PPT
Chapter 11 Metrics for process and projects.ppt
PPTX
Cost estimation techniques
PPTX
Software_Engineering_Metrics_and_Project_Management.pptx
PPT
Software metrics
PPTX
The Dark Side of Code Metrics
PDF
Software code metrics
PPT
Lecture3
PDF
Improving your CFML code quality
Unit3_Software-MDFJHGFUGJFSJDFMHGSAD,MFKJASDFH,ADSFGAKSIF,AWKJEHGF,Aetrics.pptx
source code metrics and other maintenance tools and techniques
Algorithm ExampleFor the following taskUse the random module .docx
Software metrics
Software metrics
software engineering module i & ii.pptx
Sw metrics for regression testing
A New Reusability Metric for Object-Oriented Software
Software Metrics
Software Measurement: Lecture 1. Measures and Metrics
Software Metrics Course chapter 6 at Bahir Dar University
Software engineering module 4 notes for btech and mca
Chapter 11 Metrics for process and projects.ppt
Cost estimation techniques
Software_Engineering_Metrics_and_Project_Management.pptx
Software metrics
The Dark Side of Code Metrics
Software code metrics
Lecture3
Improving your CFML code quality

More from Mohammad Reda Katby (7)

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

Recently uploaded (20)

PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PDF
Foundation of Data Science unit number two notes
PPT
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
PPTX
Computer network topology notes for revision
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PPTX
IB Computer Science - Internal Assessment.pptx
PPTX
Global journeys: estimating international migration
PDF
Fluorescence-microscope_Botany_detailed content
PDF
Introduction to Business Data Analytics.
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PPTX
1_Introduction to advance data techniques.pptx
PDF
.pdf is not working space design for the following data for the following dat...
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PPTX
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
PPT
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PDF
Mega Projects Data Mega Projects Data
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
Foundation of Data Science unit number two notes
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
Computer network topology notes for revision
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
IB Computer Science - Internal Assessment.pptx
Global journeys: estimating international migration
Fluorescence-microscope_Botany_detailed content
Introduction to Business Data Analytics.
Acceptance and paychological effects of mandatory extra coach I classes.pptx
IBA_Chapter_11_Slides_Final_Accessible.pptx
1_Introduction to advance data techniques.pptx
.pdf is not working space design for the following data for the following dat...
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
oil_refinery_comprehensive_20250804084928 (1).pptx
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
Mega Projects Data Mega Projects Data

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
  • 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/