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. 2 Who Am I? • Software Engineer at Rookout •

    Go, Java, Ruby • C#, Python, JavaScript, C++ • Sewing
  2. 5

  3. Why? 8 • We don’t know how • Intuition •

    It’s not fun • Simple code == simple bugs
  4. Unexpected Behavior 17 • Incorrect use • Something went terribly

    wrong • Integration Issues • Expectation ≠ Reality
  5. What/Why/Where 18 • Stare at the code • Read all

    the logs • Try to reproduce • Run through each line of code
  6. Fix 19 • Find a way to fix • Write

    the code • Add a test
  7. The “Research Based” Flow 20 • Our code is a

    mystery • No planning • Guessing randomly ◦ print debugging
  8. Specification 23 • Get all the information ◦ Understand the

    task ◦ Edge cases ◦ Protocols • Definition of done
  9. Planning - Design the Feature 24 • Components • Language

    to use • Design patterns • Third party libraries
  10. Planning - Setup Your Workspace 26 • An easy-to-run example

    • Up to date code • Comfortable environment
  11. 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
  12. Specification - Get All the Information • Is it even

    a bug? • Logs, Traces, Metrics • Environment 30 ➔ Specification ➔ Planning ➔ Executing
  13. Specification - Definition of Done • Reproduction • How do

    I know I fixed the bug? 31 ➔ Specification ➔ Planning ➔ Executing
  14. 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
  15. Planning - Deadlines • Multiple deadlines • What if I

    miss the deadline? 33 ➔ Specification ➔ Planning ➔ Executing
  16. Planning - Setup Your Workspace 34 • An easy-to-run example

    • Relevant code version • Comfortable environment ➔ Specification ➔ Planning ➔ Executing
  17. Executing - Use the Right Tools • Print debugging •

    Debuggers • Profilers 35 ➔ Specification ➔ Planning ➔ Executing
  18. Executing - Debug in Iterations • Practical milestones • Make

    sure you’re making progress • Validate your assumptions • Commit to git 36 ➔ Specification ➔ Planning ➔ Executing
  19. Executing - Document EVERYTHING • Document things that worked •

    Document things that didn’t • Document your thoughts • Document consistently and clearly 37 ➔ Specification ➔ Planning ➔ Executing
  20. Executing - Find and Fix Once you’ve found the bug,

    go back to the specification step 38 ➔ Specification ➔ Planning ➔ Executing
  21. 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
  22. 42

  23. 43

  24. 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
  25. 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) } } }
  26. 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
  27. Bug 49 Alice and Bob arrive at the movie theater

    with tickets for the same seat (A3).
  28. Specification - Get All the Information • Doubt the user

    • Logs 50 ➔ Specification ➔ Planning ➔ Executing
  29. Specification - Definition of Done • Reproduction • How do

    I know I fixed the bug? 52 ➔ Specification ➔ Planning ➔ Executing
  30. 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
  31. 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
  32. 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
  33. 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
  34. 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
  35. 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
  36. Planning - Setup Your Workspace 60 • An easy-to-run example

    • Relevant code version • Comfortable environment ➔ Specification ➔ Planning ➔ Executing
  37. Executing • Use the right tools • Debug in iterations

    • Document EVERYTHING • Find and fix 61 ➔ Specification ➔ Planning ➔ Executing
  38. 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