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

CSC307 Lecture 11

CSC307 Lecture 11

Introduction to Software Engineering
Software Metrics
(202407)

Code metrics are essential tools for assessing the quality and complexity of software. Today, we review size metrics, including Lines of Code (LOC), effective Lines of Code (eLOC), and logical Lines of Code (lLOC); the complexity metric that measures the number of linearly independent paths in a program called Cyclomatic Complexity (CC); and structural metrics, including Abstractness and Instability, that evaluate the balance between abstraction and concrete implementation, and the degree of dependency, respectively.

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. Reminder 2 Do not forget to submit your Individual proposal

    of What feature(s) you are implementing in your final project.
  3. FRIDAY: Work on your project NO LECTURE / NO LAB

    MONDAY: CI/CD WEDNESDAY: CI/CD + Full Review FRIDAY: Final Exam Announcement 3
  4. 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. 7
  5. 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. 8
  6. 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. 9
  7. 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. 20
  8. Cyclomatic Complexity 21 CC = Edge - Node + 2

    Or CC = ConditionalNodes + 1
  9. 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 22
  10. 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 23
  11. Abstractness of a Package • 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 31
  12. 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). 32
  13. 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| 34
  14. Distance 35 Abstract Concrete Stable Hard to Change Only incoming

    dependencies Unstable Changeable Only outgoing dependencies the m ain sequence Painful Useless 0 1 1 0 Instability Abstractness
  15. For each class: LOC eLOC lLOC Max CC A I

    D Draw the Distance Chart Reminder 42
  16. 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.