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

CSC309 Lecture 06

CSC309 Lecture 06

Software Engineering II
Code Review I
(202301)

Javier Gonzalez-Sanchez
PRO

January 22, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs
    CSC 309
    Software Engineering II
    Lecture 06:
    Code Review
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    www.javiergs.com
    Building 14 -227
    Office Hours: By appointment

    View Slide

  2. jgs
    Previously …

    View Slide

  3. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 3
    Metrics
    Size
    LOC
    eLOC
    lLOC
    Understandability
    Comments
    Whitespaces
    Complexity
    Average, Max, Min LOC
    Interface Complexity
    Cyclomatic Complexity
    Software Metrics

    View Slide

  4. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 4
    Structural Metrics
    Abstract
    concrete
    Stable
    Hard to Change
    Only incoming dependencies
    Unstable
    Changeable
    Only outgoing dependencies

    View Slide

  5. jgs
    Code Review

    View Slide

  6. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 6
    § “Any fool can write code that a computer
    can understand. Good programmers write
    code that humans can understand”.
    -Martin Fowler
    § “Even bad code can function”.
    –Robert C. Martin
    Coding

    View Slide

  7. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 7
    § “The ratio of time spent reading vs
    writing is well over
    10:1” –
    Robert C. Martin
    Coding

    View Slide

  8. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 8
    § Describe why the change is necessary (fixes a bug, improves the user experience,
    refactors the existing code).
    § Identify ways to simplify the code while still solving the problem.
    § Offer alternative implementations,
    § Seek to understand the author's perspective.
    § Remember that you are here to provide feedback, not to be a gatekeeper.
    Core Ideas for Reviewers

    View Slide

  9. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 9
    § Be grateful for the reviewer's suggestions. ("Good call. I'll make that change.")
    § Seek to understand the reviewer's perspective.
    § Extract some changes and refactoring into future stories.
    § Try to respond to every comment. And, merge once you feel confident in the code
    and its impact on the project.
    Having Your Code Reviewed

    View Slide

  10. jgs
    What Project Should We Review?

    View Slide

  11. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 11
    Team 1 2 3 4 5 6
    Files 9 18 14 7 9 15
    Methods 60 101 97 65 56 85
    Average Number of Methods per File 6.67 5.61 6.93 9.29 6.22 5.67
    Total Number of Lines 886 1804 1774 1012 579 1228
    LOC (Total) 731 1047 1047 626 538 818
    eLOC (Total) 731 849 835 512 439 660
    lLOC (Total) 689 541 541 366 311 381
    Lines of Comments 60 577 588 244 63 203
    % Comments 7.00 55.00 56.16 39.79 11.70 18.00
    % Blank Lines 11.00 10.00 13.17 12.98 7.08 10.00
    Max Cyclomatic Complexity (CC) 19 16 19 10 18 26
    Average Cyclomatic Complexity (CC) 2.30 1.00 2.26 1.86 2.00 1.70
    Parameters (Max) 5 7 3 6 7
    Parameters (Average) 0.70 0.70 0.50 1.00 1.07
    Return points (Max) 3 4 2 1 1
    Return points (Average) 1.07 1.00 1.26 1.00 1.00
    Metrics

    View Slide

  12. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 12
    Team 1 2 3 4 5 6
    Files 9 18 14 7 9 15
    Methods 60 101 97 65 56 85
    Average Number of Methods per File 6.67 5.61 6.93 9.29 6.22 5.67
    Total Number of Lines 886 1804 1774 1012 579 1228
    LOC (Total) 731 1047 1047 626 538 818
    eLOC (Total) 731 849 835 512 439 660
    lLOC (Total) 689 541 541 366 311 381
    Lines of Comments 60 577 588 244 63 203
    % Comments 7.00 55.00 56.16 39.79 11.70 18.00
    % Blank Lines 11.00 10.00 13.17 12.98 7.08 10.00
    Max Cyclomatic Complexity (CC) 19 16 19 10 18 26
    Average Cyclomatic Complexity (CC) 2.30 1.00 2.26 1.86 2.00 1.70
    Parameters (Max) 5 7 3 6 7
    Parameters (Average) 0.70 0.70 0.50 1.00 1.07
    Return points (Max) 3 4 2 1 1
    Return points (Average) 1.07 1.00 1.26 1.00 1.00
    Metrics

    View Slide

  13. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 13
    Team 05 · Features

    View Slide

  14. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 14
    Team 03 · Features

    View Slide

  15. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 15
    Let’s Work

    View Slide

  16. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 16
    § Check Javadoc for Classes and Methods
    § Check to name classes, methods, and variables.
    § Be suspicious of any static element and ask, Does this really need to be
    static?
    Static is dangerous and can drive you to the
    Structural Programming model, and you want to do
    Object-Oriented.
    § Is it DRY?
    § Is it KIS?
    Summary (par 1 /2 )

    View Slide

  17. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 17
    § Check connections (inheritance, having, using)
    § Are these global variables needed as global?
    § Should this be delegation or inheritance?
    § Be careful about what is shared on the Blackboard.
    Blackboard is dangerous; it can make you forget
    encapsulation and drive you to the everyone have
    access to everything approach.
    § Check for Observer pattern misuse or overuse
    Summary (par 1 /2 )

    View Slide

  18. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 18
    Questions

    View Slide

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

    View Slide

  20. jgs

    View Slide

  21. jgs
    CSC 309
    Software Engineering II
    Lab 06:
    Code Review
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    www.javiergs.com
    Building 14 -227
    Office Hours: By appointment

    View Slide

  22. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 22
    Think about this
    Add a draft Code Review to your
    report for Assignment 01.
    Nothing to submit today

    View Slide

  23. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 23
    Let’s Work

    View Slide

  24. jgs
    CSC 309 Software Engineering II
    Javier Gonzalez-Sanchez, Ph.D.
    [email protected]
    Winter 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