SlideShare a Scribd company logo
1 of 18
Download to read offline
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

What's hot (20)

Software Quality Assurance
Software Quality Assurance Software Quality Assurance
Software Quality Assurance
 
Bug life cycle
Bug life cycleBug life cycle
Bug life cycle
 
Static analysis
Static analysisStatic analysis
Static analysis
 
Secure Coding and Threat Modeling
Secure Coding and Threat ModelingSecure Coding and Threat Modeling
Secure Coding and Threat Modeling
 
Software Quality Assurance in software engineering
Software Quality Assurance in software engineeringSoftware Quality Assurance in software engineering
Software Quality Assurance in software engineering
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Software Development Life Cycle-SDLC
Software Development Life Cycle-SDLCSoftware Development Life Cycle-SDLC
Software Development Life Cycle-SDLC
 
Software testing
Software testingSoftware testing
Software testing
 
Chapter 5 Software Quality Assurance-Finalised_BW.ppt
Chapter 5 Software Quality Assurance-Finalised_BW.pptChapter 5 Software Quality Assurance-Finalised_BW.ppt
Chapter 5 Software Quality Assurance-Finalised_BW.ppt
 
Sdlc
SdlcSdlc
Sdlc
 
Software Reliability
Software ReliabilitySoftware Reliability
Software Reliability
 
How To Improve Quality With Static Code Analysis
How To Improve Quality With Static Code Analysis How To Improve Quality With Static Code Analysis
How To Improve Quality With Static Code Analysis
 
Code review
Code reviewCode review
Code review
 
Software quality assurance
Software quality assuranceSoftware quality assurance
Software quality assurance
 
Whitebox testing
Whitebox testingWhitebox testing
Whitebox testing
 
Software Configuration Management (SCM)
Software Configuration Management (SCM)Software Configuration Management (SCM)
Software Configuration Management (SCM)
 
Software testing & Quality Assurance
Software testing & Quality Assurance Software testing & Quality Assurance
Software testing & Quality Assurance
 
Testing Metrics
Testing MetricsTesting Metrics
Testing Metrics
 
System testing
System testingSystem testing
System testing
 
Unit 8-risk manaegement (1) -
Unit 8-risk manaegement (1) - Unit 8-risk manaegement (1) -
Unit 8-risk manaegement (1) -
 

Viewers also liked

Principal 4 Enabling A Holistic Approach
Principal 4 Enabling A Holistic ApproachPrincipal 4 Enabling A Holistic Approach
Principal 4 Enabling A Holistic ApproachMohammad Reda Katby
 
Geospatial analytics data science sg meetup
Geospatial analytics   data science sg meetupGeospatial analytics   data science sg meetup
Geospatial analytics data science sg meetupNUS-ISS
 

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

01 intro to algorithm--updated 2015
01 intro to algorithm--updated 201501 intro to algorithm--updated 2015
01 intro to algorithm--updated 2015Hira Gul
 
Design and Analysis Algorithms.pdf
Design and Analysis Algorithms.pdfDesign and Analysis Algorithms.pdf
Design and Analysis Algorithms.pdfHarshNagda5
 
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 onessuserb7c8b8
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptracha49
 
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.pptBhargaviDalal4
 
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 structureSelf-Employed
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxJeevaMCSEKIOT
 
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.pptKirti Verma
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsAkhil Kaushik
 
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 ProcessDr. Syed Hassan Amin
 

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

Global Artificial Intelligence (AI) Index
Global Artificial Intelligence (AI) IndexGlobal Artificial Intelligence (AI) Index
Global Artificial Intelligence (AI) IndexMohammad Reda Katby
 
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 ManagementMohammad Reda Katby
 
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 FrameworkMohammad Reda Katby
 
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-EndMohammad Reda Katby
 
Cobit5 Principal 1 Meeting Stakeholder Needs
Cobit5 Principal 1 Meeting Stakeholder NeedsCobit5 Principal 1 Meeting Stakeholder Needs
Cobit5 Principal 1 Meeting Stakeholder NeedsMohammad 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

Decoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis modelDecoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis modelBoston Institute of Analytics
 
Role of Consumer Insights in business transformation
Role of Consumer Insights in business transformationRole of Consumer Insights in business transformation
Role of Consumer Insights in business transformationAnnie Melnic
 
Decoding Patterns: Customer Churn Prediction Data Analysis Project
Decoding Patterns: Customer Churn Prediction Data Analysis ProjectDecoding Patterns: Customer Churn Prediction Data Analysis Project
Decoding Patterns: Customer Churn Prediction Data Analysis ProjectBoston Institute of Analytics
 
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Boston Institute of Analytics
 
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...Boston Institute of Analytics
 
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdfEnglish-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdfblazblazml
 
Rithik Kumar Singh codealpha pythohn.pdf
Rithik Kumar Singh codealpha pythohn.pdfRithik Kumar Singh codealpha pythohn.pdf
Rithik Kumar Singh codealpha pythohn.pdfrahulyadav957181
 
Introduction to Mongo DB-open-­‐source, high-­‐performance, document-­‐orient...
Introduction to Mongo DB-open-­‐source, high-­‐performance, document-­‐orient...Introduction to Mongo DB-open-­‐source, high-­‐performance, document-­‐orient...
Introduction to Mongo DB-open-­‐source, high-­‐performance, document-­‐orient...boychatmate1
 
Statistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdfStatistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdfnikeshsingh56
 
World Economic Forum Metaverse Ecosystem By Utpal Chakraborty.pdf
World Economic Forum Metaverse Ecosystem By Utpal Chakraborty.pdfWorld Economic Forum Metaverse Ecosystem By Utpal Chakraborty.pdf
World Economic Forum Metaverse Ecosystem By Utpal Chakraborty.pdfsimulationsindia
 
Non Text Magic Studio Magic Design for Presentations L&P.pdf
Non Text Magic Studio Magic Design for Presentations L&P.pdfNon Text Magic Studio Magic Design for Presentations L&P.pdf
Non Text Magic Studio Magic Design for Presentations L&P.pdfPratikPatil591646
 
DATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etcDATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etclalithasri22
 
Digital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksDigital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksdeepakthakur548787
 
IBEF report on the Insurance market in India
IBEF report on the Insurance market in IndiaIBEF report on the Insurance market in India
IBEF report on the Insurance market in IndiaManalVerma4
 
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...Jack Cole
 
Digital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdfDigital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdfNicoChristianSunaryo
 
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Boston Institute of Analytics
 
modul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptxmodul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptxaleedritatuxx
 

Recently uploaded (20)

2023 Survey Shows Dip in High School E-Cigarette Use
2023 Survey Shows Dip in High School E-Cigarette Use2023 Survey Shows Dip in High School E-Cigarette Use
2023 Survey Shows Dip in High School E-Cigarette Use
 
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis modelDecoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis model
 
Role of Consumer Insights in business transformation
Role of Consumer Insights in business transformationRole of Consumer Insights in business transformation
Role of Consumer Insights in business transformation
 
Decoding Patterns: Customer Churn Prediction Data Analysis Project
Decoding Patterns: Customer Churn Prediction Data Analysis ProjectDecoding Patterns: Customer Churn Prediction Data Analysis Project
Decoding Patterns: Customer Churn Prediction Data Analysis Project
 
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
 
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
 
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdfEnglish-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
 
Rithik Kumar Singh codealpha pythohn.pdf
Rithik Kumar Singh codealpha pythohn.pdfRithik Kumar Singh codealpha pythohn.pdf
Rithik Kumar Singh codealpha pythohn.pdf
 
Introduction to Mongo DB-open-­‐source, high-­‐performance, document-­‐orient...
Introduction to Mongo DB-open-­‐source, high-­‐performance, document-­‐orient...Introduction to Mongo DB-open-­‐source, high-­‐performance, document-­‐orient...
Introduction to Mongo DB-open-­‐source, high-­‐performance, document-­‐orient...
 
Statistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdfStatistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdf
 
Data Analysis Project: Stroke Prediction
Data Analysis Project: Stroke PredictionData Analysis Project: Stroke Prediction
Data Analysis Project: Stroke Prediction
 
World Economic Forum Metaverse Ecosystem By Utpal Chakraborty.pdf
World Economic Forum Metaverse Ecosystem By Utpal Chakraborty.pdfWorld Economic Forum Metaverse Ecosystem By Utpal Chakraborty.pdf
World Economic Forum Metaverse Ecosystem By Utpal Chakraborty.pdf
 
Non Text Magic Studio Magic Design for Presentations L&P.pdf
Non Text Magic Studio Magic Design for Presentations L&P.pdfNon Text Magic Studio Magic Design for Presentations L&P.pdf
Non Text Magic Studio Magic Design for Presentations L&P.pdf
 
DATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etcDATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etc
 
Digital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksDigital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing works
 
IBEF report on the Insurance market in India
IBEF report on the Insurance market in IndiaIBEF report on the Insurance market in India
IBEF report on the Insurance market in India
 
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
 
Digital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdfDigital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdf
 
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
 
modul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptxmodul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptx
 

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/