Slide 1

Slide 1 text

Debugging, the Developer Way Yarden Laifenfeld @yardenlaif

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Non Breaking Breakpoints 3

Slide 4

Slide 4 text

4 I love debugging. wtf?

Slide 5

Slide 5 text

5

Slide 6

Slide 6 text

6 1/30

Slide 7

Slide 7 text

7 50%

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Unexpected Behavior 10 ● Incorrect use

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Bad Response 12 CLICK ME DON’T CLICK ME

Slide 13

Slide 13 text

Unexpected Behavior 13 ● Incorrect use ● Something went terribly wrong

Slide 14

Slide 14 text

Something Went Terribly Wrong 14

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Integration Issues 16

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

21 Approach debugging like writing a feature

Slide 22

Slide 22 text

Writing a Feature 22 ● Specification ● Planning ● Executing

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Executing 27 ● Develop in iterations ● Document as you code

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Debugging a Bug 29 ● Specification ● Planning ● Executing

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

40 Plan Proportionately

Slide 41

Slide 41 text

41 Let’s See it in Action!

Slide 42

Slide 42 text

42

Slide 43

Slide 43 text

43

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

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) } } }

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

Specification - Logs 51

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

Specification - Reproduction 53

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

Verify UserCart and DB mark the same seats at checkout 63

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

65 Have Fun!

Slide 66

Slide 66 text

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