Skip to content

Instantly share code, notes, and snippets.

@telegraham
Last active November 23, 2019 13:47
Show Gist options
  • Save telegraham/9cf48fab6511a310d51334c11a982f0c to your computer and use it in GitHub Desktop.
Save telegraham/9cf48fab6511a310d51334c11a982f0c to your computer and use it in GitHub Desktop.

How to debug

  1. Replicate the bug (multiple times). Investigate: When does it happen? Describe the bug:
    • When I do X
    • Y happens
    • But I expected (wanted) Z to happen
  2. Form a hypothesis or educated guess about WHY the bug is happening
    • Read any errors, carefully — use debugging tools to fully understand what the error is telling you
    • Use your past experience with similar bugs to come up with ideas
  3. Pick the most likely hypothesis
    • If you have a reason, a gut feeling, or a favorite, use those to guide you (those factors are listed roughly in order of how well you can rely on them to guide you)
  4. Test a hypothesis
    • Use debugging tools to investigate the values of variables, arguments, and return values, the order your code executes in, and how often each piece runs
    • As you go, think through what you expect the results of each test to be. When the results of your testing don't match your expectations, that's a sign that you're getting closer to the source of the bug.
    • If your hypothesis is supported by the results of the tests, continue to 5
    • If not, try a different hypothesis (or make a new one) until you find a way to explain what's happening
  5. ONLY only once you have a tested and supported hypothesis, try a fix based on that hypothesis
    • If it worked, rejoice!
    • If it didn't, remove your attempted fix, and go back to step 3 (or 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment