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

Debugging

 Debugging

Presentation about debugging for people just learning to program.

9e9c31ccda3071a0448aef383d16fcd3?s=128

sharnik

June 17, 2015
Tweet

Transcript

  1. Wojciech @sharnik haikuco.de

  2. Programming is like riding a bike.

  3. Except the bike is on fire and you're on fire

    and everything is on fire and you're actually in hell.
  4. None
  5. Main programming tasks: » Adding bugs » Removing bugs

  6. Debugging

  7. Know what you're trying to do

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

  9. Workflow

  10. Reproduce the error

  11. Make a hypothesis

  12. Fix

  13. Profit

  14. If that didn't help, rollback

  15. Techniques

  16. Puts debugging class Calculator def add(a, b) puts a puts

    b a + b end end result = Calculator.new.add(2, 3) puts result
  17. 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"
  18. 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
  19. debugger: pry + byebug require 'pry-byebug' class Calculator def add(a,

    b) binding.pry a + b end end Calculator.new.add(2, 3)
  20. Strategies

  21. "Wolf fence" algorithm

  22. Rubber duck debugging

  23. Practice

  24. Exercise gist.github.com/sharnik/2aedd681e6bcf81a7697 Remember » understand expectations » pinpoint where the

    bug is » find what the bug is » fix it