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

Debugging, the Developer Way

Debugging, the Developer Way

Yarden Laifenfeld

March 12, 2023
Tweet

More Decks by Yarden Laifenfeld

Other Decks in Programming

Transcript

  1. Debugging, the
    Developer Way
    Yarden Laifenfeld
    @yardenlaif

    View full-size slide

  2. 2
    Who Am I?
    • Software Engineer at Rookout
    • Go, Java, Ruby
    • C#, Python, JavaScript, C++
    • Sewing

    View full-size slide

  3. Non Breaking Breakpoints
    3

    View full-size slide

  4. 4
    I love debugging.
    wtf?

    View full-size slide

  5. Why?
    8
    ● We don’t know how
    ● Intuition
    ● It’s not fun
    ● Simple code == simple bugs

    View full-size slide

  6. The Flow
    9
    ● Unexpected behavior
    ● What/Why/Where?
    ● Fix

    View full-size slide

  7. Unexpected Behavior
    10
    ● Incorrect use

    View full-size slide

  8. UI/UX Issue
    11
    CLICK
    ME
    DON’T
    CLICK
    ME

    View full-size slide

  9. Bad Response
    12
    CLICK
    ME
    DON’T
    CLICK
    ME

    View full-size slide

  10. Unexpected Behavior
    13
    ● Incorrect use
    ● Something went terribly wrong

    View full-size slide

  11. Something Went Terribly Wrong
    14

    View full-size slide

  12. Unexpected Behavior
    15
    ● Incorrect use
    ● Something went terribly wrong
    ● Integration Issues

    View full-size slide

  13. Integration Issues
    16

    View full-size slide

  14. Unexpected Behavior
    17
    ● Incorrect use
    ● Something went terribly wrong
    ● Integration Issues
    ● Expectation ≠ Reality

    View full-size slide

  15. What/Why/Where
    18
    ● Stare at the code
    ● Read all the logs
    ● Try to reproduce
    ● Run through each line of code

    View full-size slide

  16. Fix
    19
    ● Find a way to fix
    ● Write the code
    ● Add a test

    View full-size slide

  17. The “Research Based” Flow
    20
    ● Our code is a mystery
    ● No planning
    ● Guessing randomly
    ○ print debugging

    View full-size slide

  18. 21
    Approach debugging
    like writing a feature

    View full-size slide

  19. Writing a Feature
    22
    ● Specification
    ● Planning
    ● Executing

    View full-size slide

  20. Specification
    23
    ● Get all the information
    ○ Understand the task
    ○ Edge cases
    ○ Protocols
    ● Definition of done

    View full-size slide

  21. Planning - Design the Feature
    24
    ● Components
    ● Language to use
    ● Design patterns
    ● Third party libraries

    View full-size slide

  22. Planning - Deadlines
    25
    ● Multiple deadlines
    ● What if I miss the deadline?

    View full-size slide

  23. Planning - Setup Your Workspace
    26
    ● An easy-to-run example
    ● Up to date code
    ● Comfortable environment

    View full-size slide

  24. Executing
    27
    ● Develop in iterations
    ● Document as you code

    View full-size slide

  25. Writing a Feature
    28
    ● Specification
    ○ Get all the information
    ○ Definition of done
    ● Planning
    ○ Design the feature
    ○ Deadlines
    ○ Setup your workplace
    ● Executing
    ○ Develop in iterations
    ○ Document as you code

    View full-size slide

  26. Debugging a Bug
    29
    ● Specification
    ● Planning
    ● Executing

    View full-size slide

  27. Specification - Get All the Information
    ● Is it even a bug?
    ● Logs, Traces, Metrics
    ● Environment
    30
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  28. Specification - Definition of Done
    ● Reproduction
    ● How do I know I fixed the bug?
    31
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  29. Planning - Design the Debugging
    Process
    ● If I wanted to purposefully create
    this bug, how would I do that?
    ● Multiple debugging vectors
    ○ Practical milestones
    32
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  30. Planning - Deadlines
    ● Multiple deadlines
    ● What if I miss the deadline?
    33
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  31. Planning - Setup Your Workspace
    34
    ● An easy-to-run example
    ● Relevant code version
    ● Comfortable environment
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  32. Executing - Use the Right Tools
    ● Print debugging
    ● Debuggers
    ● Profilers
    35
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  33. Executing - Debug in Iterations
    ● Practical milestones
    ● Make sure you’re making progress
    ● Validate your assumptions
    ● Commit to git
    36
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  34. Executing - Document EVERYTHING
    ● Document things that worked
    ● Document things that didn’t
    ● Document your thoughts
    ● Document consistently and clearly
    37
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  35. Executing - Find and Fix
    Once you’ve found the bug, go back
    to the specification step
    38
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  36. Debugging a Bug
    39
    ● Specification
    ○ Get all the information
    ○ Definition of done
    ● Planning
    ○ Design the debugging process
    ○ Deadlines
    ○ Setup your workplace
    ● Executing
    ○ Develop in iterations
    ○ Document as you debug
    ○ Use the right tools
    ○ Fix the bug

    View full-size slide

  37. 40
    Plan
    Proportionately

    View full-size slide

  38. 41
    Let’s See it in Action!

    View full-size slide

  39. 44
    Seats DB
    getAvailableSeats()
    reserve(id, seats)
    checkout(id)
    cancel(id)

    View full-size slide

  40. Seat Selection Flow
    45
    ● UserCart calls DB.reserve(id, seats)
    ● DB checks if seats are available:
    ○ Not available: throws an error
    ○ Available: marks seats as reserved
    ■ Previous seats are discarded
    ● UserCart adds seats to list of reserved seats

    View full-size slide

  41. 46
    func select_seat(seat) {
    thread {
    new_seats = this.seats + seat
    serialized = new_seats.serialize()
    try {
    db.reserve(this.id, serialized)
    this.seats.add(seat)
    }
    }
    }

    View full-size slide

  42. Checkout Seat Flow
    47
    ● UserCart calls DB.checkout (id)
    ● DB marks all reserved seats associated with id
    as taken
    ● UserCart sends tickets for all seats in list of
    reserved seats

    View full-size slide

  43. 48
    func checkout() {
    db.checkout(this.id)
    send_tickets(this.seats)
    }

    View full-size slide

  44. Bug
    49
    Alice and Bob arrive at the movie theater with
    tickets for the same seat (A3).

    View full-size slide

  45. Specification - Get All the Information
    ● Doubt the user
    ● Logs
    50
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  46. Specification - Logs
    51

    View full-size slide

  47. Specification - Definition of Done
    ● Reproduction
    ● How do I know I fixed the bug?
    52
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  48. Specification - Reproduction
    53

    View full-size slide

  49. Planning - Design the Debugging
    Process
    ● If I wanted to purposefully create
    this bug, how would I do that?
    ● Multiple debugging vectors
    ○ Practical milestones
    54
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  50. Checkout Seat Flow
    55
    Seat Selection
    ● UserCart calls DB.reserve(id, seats)
    ● DB checks if seats are available:
    ○ Not available: throws an error
    ○ Available: marks seats as reserved (previous seats are discarded)
    ● UserCart adds seats to list of reserved seats
    Checkout
    ● UserCart calls DB.checkout(id)
    ● DB marks all reserved seats associated with id as taken
    ● UserCart sends tickets for all seats in list of reserved seats

    View full-size slide

  51. Planning - Debugging Vectors
    ● DB.reserve doesn’t reserve seats
    ● UserCart sends the wrong seats to reserve
    ● DB doesn’t checkout the correct seats
    ● DB doesn’t mark reserved seats as taken
    correctly
    ● UserCart sends tickets for wrong seats
    56
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  52. Planning - Debugging Vectors
    1. DB doesn’t mark reserved seats as taken
    correctly
    2. DB doesn’t checkout the correct seats
    3. DB.reserve doesn’t reserve seats
    57
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  53. Planning - Practical Milestones
    1. DB doesn’t mark reserved seats as taken
    correctly
    a. Sanity check DB.checkout()
    b. Stress check DB.checkout()
    2. DB doesn’t checkout the correct seats
    a. Verify UserCart and DB mark the same
    seats at checkout
    3. DB.reserve doesn’t reserve seats
    58
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  54. Planning - Deadlines
    1. DB doesn’t mark reserved seats as taken
    correctly
    a. Sanity check DB.checkout() - 2 min.
    b. Stress check DB.checkout() - 5 min.
    2. DB doesn’t checkout the correct seats
    a. Verify UserCart and DB mark the same
    seats at checkout - 10 min.
    3. DB.reserve doesn’t reserve seats
    59
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  55. Planning - Setup Your Workspace
    60
    ● An easy-to-run example
    ● Relevant code version
    ● Comfortable environment
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  56. Executing
    ● Use the right tools
    ● Debug in iterations
    ● Document EVERYTHING
    ● Find and fix
    61
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  57. Executing
    1. DB doesn’t mark reserved seats as taken
    correctly
    a. Sanity check DB.checkout() ✔
    b. Stress check DB.checkout() ✔
    2. DB doesn’t checkout the correct seats
    a. Verify UserCart and DB mark the same
    seats at checkout
    3. DB.reserve doesn’t reserve seats
    62
    ➔ Specification
    ➔ Planning
    ➔ Executing

    View full-size slide

  58. Verify UserCart and DB mark the same seats
    at checkout
    63

    View full-size slide

  59. The Bug & The Fix
    ● Try it yourself!
    ● Solution: @yardenlaif
    64

    View full-size slide

  60. Thank You
    @yardenlaif
    hachyderm.io/@yarden
    yardenlaif.com

    View full-size slide