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

Programming is Debugging, So Debug Better

Programming is Debugging, So Debug Better

Debugging: The schedule destroyer, the confidence sapper, the mire in which thousands of working hours are lost every day. It's time to stop staring at those four lines of code, desperately willing the bug to appear. This session is about the philosophies that will steer you around bugs, strategies for dealing with them, and tools that can shorten a four-hour debugging session to five minutes.

Yoz Grahame

June 20, 2013
Tweet

Other Decks in Programming

Transcript

  1. What makes it remarkable is how well the software works.

    This software never crashes. It never needs to be re-booted. This software is bug-free. It is perfect, as perfect as human beings have achieved. Consider these stats: the last three versions of the program – each 420,000 lines long – had just one error each. The last 11 versions of this software had a total of 17 errors. Commercial programs of equivalent complexity would have 5,000 errors. –– Charles Fishman, “They Write the Right Stuff”, Fast Company Magazine, December 1996
  2. “Take the upgrade of the software to permit the shuttle

    to navigate with Global Positioning Satellites, a change that involves just 1.5% of the program, or 6,366 lines of code. The specs for that one change run 2,500 pages, a volume thicker than a phone book. The specs for the current program fill 30 volumes and run 40,000 pages.”
  3. What makes it remarkable is how well the software works.

    This software never crashes. It never needs to be re-booted. This software is bug-free. It is perfect, as perfect as human beings have achieved. Consider these stats: the last three versions of the program – each 420,000 lines long – had just one error each. The last 11 versions of this software had a total of 17 errors. Commercial programs of equivalent complexity would have 5,000 errors. –– Charles Fishman, “They Write the Right Stuff”, Fast Company Magazine, December 1996 known
  4. Programming is the art of algorithm design and the craft

    of debugging errant code. In the words of the great John Backus, inventor of the Fortran programming language: “You need the willingness to fail all the time. You have to generate many ideas and then you have to work very hard only to discover that they don’t work. And you keep doing that over and over until you find one that does work.” –– Ellen Ullman, “How to Be a ‘Woman Programmer’”, The New York Times, May 18 2013
  5. which mostly consist of A Whole Load Of Seemingly-Obvious Tips

    Which All Beginners Would Be Much Better Off Knowing Yet Even Experienced Engineers Usually Miss
  6. 0 25 50 75 100 2010 2011 2012 2013 2014

    (projected) Amount of cake and ponies in my life Amount of debugging in my life
  7. = =

  8. Errors usually have: A line number An error type A

    subject A failing operation Additional context A hint for fixing (if you’re lucky)
  9. Errors usually have: A line number An error type A

    subject A failing operation Additional context A hint for fixing (if you’re lucky) Engineers usually ignore at least one of these.
  10. Compiler errors & warnings are your friends. (This is why

    some people prefer strongly-typed languages)
  11. “If you’re not getting a stack trace, print one that

    you can look through...” Jose Valim, creator of the Elixir language and Devise authentication framework http://www.flickr.com/photos/levycarneiro/4016052036/
  12. “... and if you’re a Java developer, print the stack

    trace out on paper and take it home to read.”
  13. Perfect for those situations where you have an unusual error

    and a particular framework (or combination)
  14. “Visualising the code with diagrams usually helps me think through

    a problem.” Valerie Aurora, leader of The Ada Initiative, Linux filesystem hacker
  15. Tests are great because Super-fast iteration! Automated setup & teardown

    Green/red is a definite yes/no Prevent regressions Remove the daunt & bugs from refactoring Great for metrics & analysis
  16. Prevent bugs with automated analysis Linters check your code for

    common style problems. Coverage checkers show you how much of your code is being tested by your tests. Complexity analysis tools highlight code which is hard to test and may hide bugs. ... plus loads of language/framework-specific analysis tools!
  17. Tests & analysis automated quickly and cheaply: Run tests automatically

    with a Continuous Integration service: Travis-CI, CircleCI, Solana Static code analysis: CodeClimate for Ruby, many open source tools for all languages Run web app tests across different browsers: Selenium, Sauce Labs, Browserling
  18. “I use tests in combination with the Divide-and-Conquer approach.” Jim

    Weirich, creator of Rake and other fine Ruby tools http://www.flickr.com/photos/fraserspeirs/4473763733/
  19. How Jim and Shreyas fixed it: Isolate by making the

    test as small as possible Further isolate by splitting up the method being tested It’s caused by data? Split up the data!
  20. How Jim and Shreyas fixed it: Isolate by making the

    test as small as possible Further isolate by splitting up the method being tested It’s caused by data? Split up the data! It turned out to be an error from Chrome’s JSON parser. Over a day’s ponies stolen!
  21. “You have to treat it like empirical science: go through

    your assumptions and try to disprove each one.” Lisa Dusseault, ex-Apps Area Director for IETF; also Xythos, OSAF, Linden Lab
  22. I asked these top Ruby coders... Jim Weirich Jose Valim

    Steve Klabnik Aaron Patterson ... what’s your #1 debugging tool?
  23. and they said... puts puts puts puts ... and I

    called them something rude in Yiddish.
  24. “I can never remember the commands for the Ruby debugger.”

    Jim Weirich, who has given talks about the Ruby debugger http://www.flickr.com/photos/fraserspeirs/4473763733/
  25. print sucks Awkward to insert Dumb and non-queryable Hard to

    spot in output Easy to commit by accident Remind me which decade we’re in?
  26. ... but the point is: Traditional debuggers have problems Too

    slow to invoke and get to the relevant code Step in/out/up/down dance is horrid ... and often goes wrong
  27. The worst kind of print if x.count > 3 print

    “Got here!” x.doStuff()
  28. Panorama It’s barely a proof of concept, let alone alpha

    It almost certainly won’t work out of the box It still needs proper packaging & tests If you’re still reading, I’d love some help https://github.com/yozlet/panorama
  29. Time’s up, but there’s so much more! Security holes Resource

    leaks ConcBururencgy s Performance problems Text Ệncøding Time & Date Database consistency OS-level problems Failures in production Network debugging Hardware flaws Everything else
  30. Other great OSBridge talks Debugging Without Borders - Chris McCraw

    http://opensourcebridge.org/sessions/1004 PHP for Pirates: Pillaging interactive debugging from Ruby & Javascript - Justin “bobthecow” Hileman http://opensourcebridge.org/sessions/952 What is That Process Doing? - Greg Price http://opensourcebridge.org/sessions/1069
  31. This is the way the world ends: Not with a

    bang, but a bug. Don’t let it be yours.