Slide 1

Slide 1 text

Wojciech @sharnik haikuco.de

Slide 2

Slide 2 text

Programming is like riding a bike.

Slide 3

Slide 3 text

Except the bike is on fire and you're on fire and everything is on fire and you're actually in hell.

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Main programming tasks: » Adding bugs » Removing bugs

Slide 6

Slide 6 text

Debugging

Slide 7

Slide 7 text

Know what you're trying to do

Slide 8

Slide 8 text

Inputs -> Program -> Outputs Calculator.add(2, 3) # => 5

Slide 9

Slide 9 text

Workflow

Slide 10

Slide 10 text

Reproduce the error

Slide 11

Slide 11 text

Make a hypothesis

Slide 12

Slide 12 text

Fix

Slide 13

Slide 13 text

Profit

Slide 14

Slide 14 text

If that didn't help, rollback

Slide 15

Slide 15 text

Techniques

Slide 16

Slide 16 text

Puts debugging class Calculator def add(a, b) puts a puts b a + b end end result = Calculator.new.add(2, 3) puts result

Slide 17

Slide 17 text

strings vs numbers ruby -e "x = 3; puts x" # => 3 ruby -e "x = '3'; puts x" # => 3 ruby -e "x = 3; puts x.inspect" # => 3 ruby -e "x = '3'; puts x.inspect" # => "3"

Slide 18

Slide 18 text

p: shorter puts X.inspect class Calculator def add(a, b) p a p b a + b end end result = Calculator.new.add(2, 3) p result

Slide 19

Slide 19 text

debugger: pry + byebug require 'pry-byebug' class Calculator def add(a, b) binding.pry a + b end end Calculator.new.add(2, 3)

Slide 20

Slide 20 text

Strategies

Slide 21

Slide 21 text

"Wolf fence" algorithm

Slide 22

Slide 22 text

Rubber duck debugging

Slide 23

Slide 23 text

Practice

Slide 24

Slide 24 text

Exercise gist.github.com/sharnik/2aedd681e6bcf81a7697 Remember » understand expectations » pinpoint where the bug is » find what the bug is » fix it