Presentation about debugging for people just learning to program.
Wojciech@sharnikhaikuco.de
View Slide
Programmingis like riding a bike.
Except the bike is onfire and you're onfire and everythingis on fire and you'reactually in hell.
Main programming tasks:» Adding bugs» Removing bugs
Debugging
Knowwhat you'retrying to do
Inputs -> Program -> OutputsCalculator.add(2, 3)# => 5
Workflow
Reproduce theerror
Make ahypothesis
Fix
Profit
If that didn't help,rollback
Techniques
Puts debuggingclass Calculatordef add(a, b)puts aputs ba + bendendresult = Calculator.new.add(2, 3)puts result
strings vs numbersruby -e "x = 3; puts x"# => 3ruby -e "x = '3'; puts x"# => 3ruby -e "x = 3; puts x.inspect"# => 3ruby -e "x = '3'; puts x.inspect"# => "3"
p: shorter puts X.inspectclass Calculatordef add(a, b)p ap ba + bendendresult = Calculator.new.add(2, 3)p result
debugger: pry + byebugrequire 'pry-byebug'class Calculatordef add(a, b)binding.prya + bendendCalculator.new.add(2, 3)
Strategies
"Wolf fence"algorithm
Rubber duckdebugging
Practice
Exercisegist.github.com/sharnik/2aedd681e6bcf81a7697Remember» understand expectations» pinpoint where the bug is» find what the bug is» fix it