Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSC305 Lecture 06

CSC305 Lecture 06

Individual Software Design and Development
Code Metrics
(202409)

Javier Gonzalez-Sanchez

October 03, 2024
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227

    CSC 305 Individual Software Design and Development Lecture 05. Software Metrics
  2. Function Metrics • Cyclomatic Complexity. It is a quantitative measure

    of the number of linearly independent paths. • P a ths occur when "while,” "for,” "if,” "c a se," a nd "goto" keywords a ppe a r within the function. • If the source code cont a ined no control f low st a tements (condition a ls or decision points), the complexity would be 1 • If the code h a d one single-condition IF st a tement, there would be two p a ths through the code: one where the IF st a tement ev a lu a tes to TRUE a nd a nother one where it considers to be FALSE. • Two nested single-condition IFs, or one block with two conditions, would produce a complexity of 3. 13
  3. Cyclomatic Complexity 14 CC = Edge - Node + 2

    Or CC = ConditionalNodes + 1
  4. Cyclomatic Complexity i = 0; n=4; while (i<n-1) { j

    = i + 1; while (j<n) { if (A[i]<A[j]) swap(A[i], A[j]); } i=i+1; } // CC = 9 - 7 + 2 = 4 // CC = 3 + 1 = 4 (Condition nodes are 1,2 and 3 nodes) // A set of possible execution path of a program // 1, 7 // 1, 2, 6, 1, 7 // 1, 2, 3, 4, 5, 2, 6, 1, 7 // 1, 2, 3, 5, 2, 6, 1, 7 15
  5. Complexity Number Meaning 1-10 Structured and well written code 


    High Testability 
 Cost and Effort is less 10-20 Complex Code 
 Medium Testability 
 Cost and effort is Medium 20-40 Very complex Code 
 Low Testability 
 Cost and Effort are high >40 Not at all testable 
 Very high Cost and Effort Cyclomatic Complexity 16
  6. Reminder 19 Calculate metrics for 2 versions of my Paint

    App https://github.com/CSC3100/App-Paint/
  7. Part 1: For each class: LOC eLOC lLOC For each

    class, For each method: CC Reminder 20
  8. CSC 305 Individual Software Design and Development Javier Gonzalez-Sanchez, Ph.D.

    [email protected] Summer 2024 Copyright. These slides can only be used as study material for the class CSC305 at Cal Poly. They cannot be distributed or used for another purpose.