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

CSC307 Lecture 14

CSC307 Lecture 14

Introduction to Software Engineering
Software Metrics
(202307)

Javier Gonzalez-Sanchez
PRO

July 17, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs
    CSC 307
    Introduction to Software Engineering
    Lecture 14:
    Software Metrics
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    www.javiergs.com
    Building 14 -227
    Office Hours: By appointment

    View Slide

  2. jgs
    Metrics

    View Slide

  3. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 4
    Metrics
    Size
    LOC
    eLOC
    lLOC
    Complexity
    Average, Max, Min LOC
    Cyclomatic Complexity
    Software Metrics

    View Slide

  4. jgs
    Software Metrics
    Size

    View Slide

  5. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 6
    § 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.
    Size Metrics

    View Slide

  6. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 7
    § 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.
    Size Metrics

    View Slide

  7. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 8
    § 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.
    Size Metrics

    View Slide

  8. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 9
    Example

    View Slide

  9. jgs
    Test Yourselves

    View Slide

  10. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 11
    Hello World

    View Slide

  11. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 12
    BubbleSort Iterativo

    View Slide

  12. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 13
    Recursive BubbleSort

    View Slide

  13. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 14
    In Order Traversal

    View Slide

  14. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 15

    View Slide

  15. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 16

    View Slide

  16. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 17

    View Slide

  17. jgs
    Software Metrics
    Complexity

    View Slide

  18. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 19
    § Cyclomatic Complexity. It is a quantitative measure of the number of
    linearly independent paths.
    § Paths occur when "while,” "for,” "if,” "case," and "goto" keywords appear
    within the function.
    § 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 two paths
    through the code: one where the IF statement evaluates to TRUE and
    another one where it considers to be FALSE.
    § Two nested single-condition IFs, or one block with two conditions, would
    produce a complexity of 3.
    Function Metrics

    View Slide

  19. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 20
    Cyclomatic Complexity
    CC = Edge - Node + 2
    Or
    CC = ConditionalNodes + 1

    View Slide

  20. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 21
    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
    Cyclomatic Complexity

    View Slide

  21. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 22
    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

    View Slide

  22. jgs
    Compare

    View Slide

  23. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 24
    Example Sprint 2

    View Slide

  24. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 25
    Example Sprint 3

    View Slide

  25. jgs
    New Tool
    RSM

    View Slide

  26. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 27
    Resource Standard Metrics (RSM) is a source code metrics and quality
    analysis tool for ANSI C, ANSI C++, C# and Java for use on all Windows* and
    UNIX operating systems.
    1. Download RSM 7.75 Trial (Windows) here:
    http://msquaredtechnologies.com/
    RSM-Download.html
    * Install the Windows version. It includes a easy to use friendly interface (RSM
    Wizard).
    Tool

    View Slide

  27. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 28
    2. Review the user manual here
    http://msquaredtechnologies.com
    /m2wizard/RSM_Wizard_Manual.htm
    Disclaimer:
    It is a FREE tool…
    Issues counting LOCs, eLOCs,
    Issues counting conditions (syntaxis analysis)
    BUT ±0..9 does not affect in biggest projects 🧐
    Resource Standard Metrics

    View Slide

  28. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 29
    Resource Standard Metrics

    View Slide

  29. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 30
    Resource Standard Metrics

    View Slide

  30. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 31
    Example Sprint 2

    View Slide

  31. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 33
    Questions

    View Slide

  32. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 34
    Office Hours
    Tuesday and Thursday 3 - 5 pm
    But an appointment required
    Sent me an email – [email protected]

    View Slide

  33. jgs

    View Slide

  34. jgs
    CSC 307
    Introduction to Software Engineering
    Lab 14:
    Software Metrics
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    www.javiergs.com
    Building 14 -227
    Office Hours: By appointment

    View Slide

  35. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 37
    Think about this
    Calculate metrics for your
    Shape App and Cluster App

    View Slide

  36. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 38
    Let’s Work

    View Slide

  37. jgs
    CSC 307 Introduction to Software Engineering
    Javier Gonzalez-Sanchez, Ph.D.
    [email protected]
    Summer 2023
    Copyright. These slides can only be used as study material for the class CSC308 at Cal Poly.
    They cannot be distributed or used for another purpose.

    View Slide