$30 off During Our Annual Pro Sale. View Details »

CSE460 Lecture 24

CSE460 Lecture 24

Software Analysis and Design
Metrics
(202104)

Javier Gonzalez-Sanchez
PRO

July 24, 2020
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs
    CSE 460
    Software Analysis and Design
    Lecture 24: Software Quality Metrics
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    javiergs.engineering.asu.edu | javiergs.com
    PERALTA 230U
    Office Hours: By appointment

    View Slide

  2. jgs
    564 00011000
    Announcement
    § Quiz 06 is due tonight

    View Slide

  3. jgs
    564 00011000
    Quality

    View Slide

  4. jgs
    564 00011000
    Software Metrics
    § Knowing what is inside your source code is the first step in assessing the
    quality of the software product.
    § Knowing the quantity of work performed in generating the source code is
    the first step in determining the productivity of your software team.

    View Slide

  5. jgs
    564 00011000
    Software Metrics
    Metrics
    Size
    LOC
    eLOC
    lLOC
    Understandability
    Comments
    Whitespaces
    Complexity
    Average, Max, Min LOC
    Interface Complexity
    Cyclomatic Complexity

    View Slide

  6. jgs
    Size Metrics

    View Slide

  7. jgs
    564 00011000
    Size Metrics
    § LOC – Lines of Code Metric. Including lines of a single brace or
    parenthesis.
    § LOC are used to create time and cost estimates.
    § LOC are a tracking tool to measure the degree of progress on a module or
    project.
    § An experienced developer can gage a LOC estimate based upon
    knowledge of past productivity on projects.

    View Slide

  8. jgs
    564 00011000
    Size Metrics
    § eLOC (effective Lines of Code) Metric. Only code statements
    § An effective line of code or eLOC is the measurement of all lines that are not
    comments, blanks or standalone braces or parenthesis. These can
    inflate LOC metrics by 20 to 40 percent.
    § This metric more closely represents the quantity of work performed.

    View Slide

  9. jgs
    564 00011000
    Size Metrics
    § lLOC (logical Lines of Code) Metric.
    § These statements are terminated with a semi-colon.
    § The control line for the "for" loop contain two semi-colons but accounts for
    only one semi colon.

    View Slide

  10. jgs
    564 00011000
    Example

    View Slide

  11. jgs
    564 00011000
    About LOC per method
    § around 20 is perfect,
    § up to 50 is still fine,
    § up to 100 is critical,
    § above 150 is bad, and
    § more than 250 is
    !

    View Slide

  12. jgs
    Understandability Metrics

    View Slide

  13. jgs
    564 00011000
    Understandability Metrics
    § Comment Line Count and Comment Percent Metric
    § The degree of commenting within the source code measures the care taken
    by the programmer to make the source code and algorithms
    understandable.
    § Poorly commented code makes the maintenance phase of the software life
    cycle an extremely expensive adventure.
    § Comments can occur by themselves on a physical line or be co-mingled
    with source code. The sum of the lines of code, comments and blank lines
    often exceeds the physical line count. This is expected a when comments
    are co-mingled with source code.
    § Comment Percent = Comment Line Count / (LOC) x 100

    View Slide

  14. jgs
    564 00011000
    Understandability Metrics
    § Blank Line Count and White Space Percent Metric
    § The number of blank lines within source code determines the readability of
    the product. White space accents the logical grouping of constructs and
    variables. Programs which use few blank lines are difficult to read and
    more expensive to maintain.
    § It counts the spaces and characters within the source code. The white
    space percentage metric is another measure of readability for the source
    product.
    § White Space Percentage = (#spaces / #spaces + #characters) * 100

    View Slide

  15. jgs
    564 00011000
    Function Metrics
    § Average LOC per Function Metric. An accepted industry standard of 200
    LOC per function is desired as the average LOC per function
    § Maximum LOC per Function Metric.
    § Minimum LOC per Function Metric. A minimum LOC per function of 2 or
    less can indicate functions that may have been prototype but not yet
    complete..

    View Slide

  16. jgs
    Complexity Metrics

    View Slide

  17. jgs
    564 00011000
    Function Metrics
    § Cyclomatic Complexity. It is a quantitative measure of the number of
    linearly independent paths
    § Paths occurs when a "while", "for", "if", "case" and "goto" keywords appear
    within the function.
    § Cyclomatic Complexity = Conditional_Nodes + 1
    or
    CC = Edges - Nodes + 2 //using a Control Flow Graph

    View Slide

  18. jgs
    564 00011000
    Function Metrics
    Examples:
    § if the source code contained no control flow statements (conditionals or
    decision points), the complexity would be 1
    § If the code had one single-condition IF statement, there would be 2 paths
    through the code: one where the IF statement evaluates to TRUE and
    another one where it evaluates to FALSE
    § Two nested single-condition IFs, or one IF with two conditions, would
    produce a complexity of 3.

    View Slide

  19. jgs
    564 00011000
    Cyclomatic Complexity
    i = 0; n=4;
    while (ij = i + 1;
    while (jif (A[i]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

    View Slide

  20. jgs
    564 00011000
    Cyclomatic Complexity
    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

    View Slide

  21. jgs
    564 00011000
    Example
    § 3 files
    § 24 methods
    § 394 lines
    § 326 LOC
    § 285 eLOC
    § 182 lLOC
    § 20 Lcomments
    § Comments 5.1%
    § Blank lines 12.2%
    § Spaces: 21.0% (79% code)
    § Max CC: 6
    § Average CC: 1.46

    View Slide

  22. jgs
    Test Yourselves

    View Slide

  23. jgs
    564 00011000
    Code 1

    View Slide

  24. jgs
    564 00011000
    Code 2

    View Slide

  25. jgs
    564 00011000
    Code

    View Slide

  26. jgs
    564 00011000
    Numbers
    LOC eLOC lLOC Cyclomatic
    Complexity
    m1()
    m2()
    m3()
    m4()
    m5()
    main()
    total

    View Slide

  27. jgs
    Structural Complexity

    View Slide

  28. jgs
    564 00011000
    Example

    View Slide

  29. jgs
    564 00011000
    • Instability = Cout
    (Cin + Cout)
    Stable Abstraction Principle (SAP)

    View Slide

  30. jgs
    To be continued…

    View Slide

  31. jgs
    CSE 460 Software Analysis and Design
    Javier Gonzalez-Sanchez
    [email protected]
    Fall 2020
    Disclaimer. These slides can only be used as study material for the class CSE460 at ASU. They cannot be distributed or used for another purpose.

    View Slide