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

CSC307 Lecture 14

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

CSC307 Lecture 14

Introduction to Software Engineering
Metrics
(202505)

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 307 Introduction to Software Engineering Lecture 11. Software Metrics
  2. Single Responsibility • E a ch cl a ss or

    function should h a ve one, a nd only one, job. • Keep functions focused on a single t a sk. • Bre a k down your code into sm a ller, reus a ble modules or functions. • Ensure e a ch module or function h a s a cle a r, well-de f ined purpose. • 4
  3. Size Metrics • LOC – Lines of Code Metric. Including

    lines of a single br a ce or p a renthesis • LOC a re used to cre a te time a nd cost estim a tes. • LOC a re a tr a cking tool to me a sure the degree of progress on a module or project. • An experienced developer c a n g a ge a LOC estim a te b a sed upon knowledge of p a st productivity on projects. 12
  4. Size Metrics • eLOC – e ff ective Lines of

    Code Metric. Only code st a tements • An e ff ective line of code or eLOC is the me a surement of a ll lines th a t a re not comments, bl a nks or st a nd a lone br a ces or p a renthesis. These c a n in f l a te LOC metrics by 20 to 40 percent. • This metric more closely represents the qu a ntity of work performed. 13
  5. Size Metrics • lLOC – logic a l Lines of

    Code Metric. • These st a tements a re termin a ted with a semi-colon. • The control line for the "for" loop cont a in two semi-colons but a ccounts for only one semi colon. 14
  6. 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. 25
  7. Cyclomatic Complexity 26 CC = Edge - Node + 2

    Or CC = ConditionalNodes + 1
  8. 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 27
  9. 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 28
  10. Abstractness • It is the degree to which a cl

    a ss or p a ck a ge emph a sizes a bstr a ction over concrete implement a tion • It is a v a lue 0 to 1: • For p a ck a ges, It is the r a tio of a bstr a ct cl a sses or interf a ces to the tot a l number of cl a sses within a p a ck a ge. • For cl a sses, It is 0 for a concrete cl a ss a nd 1 for a n interf a ce or a bstr a ct cl a sses 38
  11. Instability • Indic a tes whether: ( a ) the

    item is m a inly used by others (st a ble – h a rd to ch a nge); or (b) it m a inly depends on other items (in-st a ble – ch a nge a ble). • It is a v a lue between 0 a nd 1: • 0 only incoming dependencies to • 1 (only outgoing dependencies). 39
  12. Distance • Dist a nce: how f a r a

    p a ck a ge is a w a y from the M a in Sequence • D = A + I – 1 • V a lues -1 to 1 • Absolute Dist a nce |D| 40
  13. Distance 41 Abstract Concrete Stable Hard to Change Only incoming

    dependencies Unstable Changeable Only outgoing dependencies the main sequence Painful Useless 0 1 1 0 Instability Abstractness
  14. Lab

  15. CSC 307 Introduction to Software Engineering Javier Gonzalez-Sanchez, Ph.D. [email protected]

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