Cyclomatic complexity
Code static analysis
What is it Static Analysis and why we do it ?
It's a type of code analysis done, not at execution time, that give us some metrics about :
1. Code quality
2. Design
3. Insight about vulnerabilities .
4. Bugs
Static analysis types :
1. Code style
2. Security Linting
3. Error detection
4. Duplicate code detection
5. Secret Detection
6. Comment style
7. Unused code detection
8. Complexity
Cyclomatic complexity ! Why ?
Measure the complexity of some code with more accurate metric than just volume .
Eventually we all aim to improve software quality :
1. Changeability
2. Tetability
Some theory : MacCabe function .
M = E - N + 2P
What does it mean ?
1. E = the number of edges of the graph
2. N = the number of nodes of the graph
3. P = the number of connected components
M obviously is the complexity we are trying to calculate .
If you re connect your exit point to your entry point the formula will change as follow :
M = E -N + P
Control Flow Graphs
A representation using graph notation, of all paths that might be traversed through a program
1. Each basic block represented as graph node
2. Jump targets start block , jumps end block
3. Jumps represented as directed edges
A. Allows tracing execution dependant on given inputs without running application
B. Trace data sinks back to original source
C. Data sanitized several function calls ago ? Trace the graph back and find it .
D. Help to discover and build test cases
Complexity Case 1
IF - THEN - ELSE
Complexity Case 2
WHILE LOOP
Complexity Case 3
LOOP with BREAK point
Complexity Case 4
SWITCH CASE
Complexity Up : less readability, Harder to
test , harder to mantains.
Complexity increase with the number of branches you give to your code.
What can I get from it
Checking complexity per method /function and class I can get some insight about my code
design. In Fact if a class has a high complexity it's possible that there is a violation of Single
responsibility principle . As well it's possible that will be harder as well for the class to respect
the Open Close principle.
Avoid complexity: KISS
KEEP IT SIMPLE STUPID
Try to keep it DRY !!
DO NOT REPEAT YOURSELF
Be SOLID
S.O.L.I.D :
1. Single responsibility principle
2. Open close principle
3. Liskov Substitution Principle
4. Interface Segregation Principle.
5. Dependency Inversion Principle
Links & References
JavaScript
1. http://jshint.com/
2. https://eslint.org/docs/rules/complexity.html
Python
1. http://radon.readthedocs.io/en/latest/commandline.html
2. https://www.fullstackpython.com/code-metrics.html
Nice links
https://medium.com/unbabel-dev/refactoring-a-python-codebase-using-the-single-
responsibility-principle-ed1367baefd6

More Related Content

PDF
20130523 05 - Cyclomatic complexity
PPT
L01 intro-daa - ppt1
PPTX
Algorithm and flowchart with pseudo code
PPTX
phases of algorithm
PPT
Fundamental of Algorithms
PPTX
White Box Testing And Control Flow & Loop Testing
DOCX
Which is not a step in the problem
PPTX
Flowcharts and algorithms
20130523 05 - Cyclomatic complexity
L01 intro-daa - ppt1
Algorithm and flowchart with pseudo code
phases of algorithm
Fundamental of Algorithms
White Box Testing And Control Flow & Loop Testing
Which is not a step in the problem
Flowcharts and algorithms

What's hot (18)

PDF
Algorithm
PPTX
if, while and for in Python
PPT
Model and Design
PPTX
Topic 1.4: Randomized Algorithms
PPT
Randomized Algorithms
PDF
PPT
Collatz Conjecture Research
PPTX
PPT
Equivalence partitions analysis
PPTX
Competitive Programming Guide
PPT
Boundary value analysis
PDF
Assignment # 3 computer system and Programming EC-105
PDF
EE 337 Lab 1 for Section 1 (2nd year UG)
PDF
Algorithmic problem solving
PDF
Code optimization lecture
PPT
PDF
Video caption generation via seq-to-seq model (TensorFlow implementation)
Algorithm
if, while and for in Python
Model and Design
Topic 1.4: Randomized Algorithms
Randomized Algorithms
Collatz Conjecture Research
Equivalence partitions analysis
Competitive Programming Guide
Boundary value analysis
Assignment # 3 computer system and Programming EC-105
EE 337 Lab 1 for Section 1 (2nd year UG)
Algorithmic problem solving
Code optimization lecture
Video caption generation via seq-to-seq model (TensorFlow implementation)
Ad

Similar to Cyclomatic complexity (20)

PPT
UNIT-1-PPTS-DAA.ppt
PPT
UNIT-1-PPTS-DAA.ppt
PPT
Introduction to Design Algorithm And Analysis.ppt
PPT
UNIT 1- Design Analysis of algorithms and its working
PPT
UNIT-1-PPTS-DAA INTRO WITH DIVIDE AND CONQUER
PPT
UNIT-1-PPTS-DAA_INTRODUCTION_TO_DAA_GH.ppt
PPT
UNIT-1-PPT-DESIGN AND ANALYSIS OF ALGORITHMS
PDF
Introduction to Problem Solving Techniques
PDF
Problem solving techniques in c language
PDF
GE3151 PSPP _Unit 1 notes and Question bank.pdf
PPT
Assessing Unit Test Quality
PPTX
Introduction to problem solving Techniques
PPTX
Symbolic Execution And KLEE
PDF
Clean code: understanding Boundaries and Unit Tests
PDF
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
PPT
Unit 1 python (2021 r)
PDF
ppts foe design and analysis of algorithm
PPTX
Improving Code Quality Through Effective Review Process
PPTX
Whitebox Testing,Types,Different techniques
PDF
UNIT-1-PdjfjfjfjfjfjfjfjfjfjfjPTS-DAA.pdf
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
Introduction to Design Algorithm And Analysis.ppt
UNIT 1- Design Analysis of algorithms and its working
UNIT-1-PPTS-DAA INTRO WITH DIVIDE AND CONQUER
UNIT-1-PPTS-DAA_INTRODUCTION_TO_DAA_GH.ppt
UNIT-1-PPT-DESIGN AND ANALYSIS OF ALGORITHMS
Introduction to Problem Solving Techniques
Problem solving techniques in c language
GE3151 PSPP _Unit 1 notes and Question bank.pdf
Assessing Unit Test Quality
Introduction to problem solving Techniques
Symbolic Execution And KLEE
Clean code: understanding Boundaries and Unit Tests
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
Unit 1 python (2021 r)
ppts foe design and analysis of algorithm
Improving Code Quality Through Effective Review Process
Whitebox Testing,Types,Different techniques
UNIT-1-PdjfjfjfjfjfjfjfjfjfjfjPTS-DAA.pdf
Ad

Recently uploaded (20)

PPTX
Monitoring Stack: Grafana, Loki & Promtail
PDF
Cost to Outsource Software Development in 2025
PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PDF
Topaz Photo AI Crack New Download (Latest 2025)
PDF
AI Guide for Business Growth - Arna Softech
PDF
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
PPTX
Tech Workshop Escape Room Tech Workshop
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PPTX
CNN LeNet5 Architecture: Neural Networks
PDF
Autodesk AutoCAD Crack Free Download 2025
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PDF
Types of Token_ From Utility to Security.pdf
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Website Design Services for Small Businesses.pdf
PDF
MCP Security Tutorial - Beginner to Advanced
PPTX
Trending Python Topics for Data Visualization in 2025
PDF
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PPTX
GSA Content Generator Crack (2025 Latest)
Monitoring Stack: Grafana, Loki & Promtail
Cost to Outsource Software Development in 2025
How Tridens DevSecOps Ensures Compliance, Security, and Agility
Topaz Photo AI Crack New Download (Latest 2025)
AI Guide for Business Growth - Arna Softech
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
Tech Workshop Escape Room Tech Workshop
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
DNT Brochure 2025 – ISV Solutions @ D365
CNN LeNet5 Architecture: Neural Networks
Autodesk AutoCAD Crack Free Download 2025
How to Use SharePoint as an ISO-Compliant Document Management System
Types of Token_ From Utility to Security.pdf
Advanced SystemCare Ultimate Crack + Portable (2025)
Oracle Fusion HCM Cloud Demo for Beginners
Website Design Services for Small Businesses.pdf
MCP Security Tutorial - Beginner to Advanced
Trending Python Topics for Data Visualization in 2025
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
GSA Content Generator Crack (2025 Latest)

Cyclomatic complexity

  • 2. What is it Static Analysis and why we do it ?
  • 3. It's a type of code analysis done, not at execution time, that give us some metrics about : 1. Code quality 2. Design 3. Insight about vulnerabilities . 4. Bugs
  • 4. Static analysis types : 1. Code style 2. Security Linting 3. Error detection 4. Duplicate code detection 5. Secret Detection 6. Comment style 7. Unused code detection 8. Complexity
  • 5. Cyclomatic complexity ! Why ? Measure the complexity of some code with more accurate metric than just volume . Eventually we all aim to improve software quality : 1. Changeability 2. Tetability
  • 6. Some theory : MacCabe function . M = E - N + 2P
  • 7. What does it mean ? 1. E = the number of edges of the graph 2. N = the number of nodes of the graph 3. P = the number of connected components M obviously is the complexity we are trying to calculate . If you re connect your exit point to your entry point the formula will change as follow : M = E -N + P
  • 8. Control Flow Graphs A representation using graph notation, of all paths that might be traversed through a program 1. Each basic block represented as graph node 2. Jump targets start block , jumps end block 3. Jumps represented as directed edges A. Allows tracing execution dependant on given inputs without running application B. Trace data sinks back to original source C. Data sanitized several function calls ago ? Trace the graph back and find it . D. Help to discover and build test cases
  • 9. Complexity Case 1 IF - THEN - ELSE
  • 11. Complexity Case 3 LOOP with BREAK point
  • 13. Complexity Up : less readability, Harder to test , harder to mantains. Complexity increase with the number of branches you give to your code.
  • 14. What can I get from it Checking complexity per method /function and class I can get some insight about my code design. In Fact if a class has a high complexity it's possible that there is a violation of Single responsibility principle . As well it's possible that will be harder as well for the class to respect the Open Close principle.
  • 15. Avoid complexity: KISS KEEP IT SIMPLE STUPID
  • 16. Try to keep it DRY !! DO NOT REPEAT YOURSELF
  • 17. Be SOLID S.O.L.I.D : 1. Single responsibility principle 2. Open close principle 3. Liskov Substitution Principle 4. Interface Segregation Principle. 5. Dependency Inversion Principle
  • 18. Links & References JavaScript 1. http://jshint.com/ 2. https://eslint.org/docs/rules/complexity.html Python 1. http://radon.readthedocs.io/en/latest/commandline.html 2. https://www.fullstackpython.com/code-metrics.html Nice links https://medium.com/unbabel-dev/refactoring-a-python-codebase-using-the-single- responsibility-principle-ed1367baefd6