25 Debugging Techniques Every Software Developer Should Master

Principles

  1. Observability. Program should output its progress so you can see which codepaths are being taken
    • Logging: delinate between log levels: TRACE/INFO/DEBUG/WARN/ERROR/FATAL
    • Tight REPL
  2. Root-cause. Always find the root cause of why the bug happened. You shouldn’t be satisfied with a surface-level reason
  3. Verification. Code should be verified

Techniques

  1. Systematic Reduction. This is done both in time-axis and space-axis:
    1. Time: which version (commit) introduced the bug?
    2. Space: which line of code introduced the bug?
  2. Static program analysis. Ranges from simple to proper:
    1. Linters
    2. Using typed languages (Algebraic Type System)
    3. Functional Programming languages
    4. Formal Methods
  3. Testing. With tests, you can make changes without fear that it’ll break something without you knowing
  4. Tight REPL. Your debugging harness should be setup for a very tight REPL loop. The longer it takes to get the feedback, the less efficient, and more frustrating.

Tools

  1. Debugger
    1. A time-travel debugger is the best, but if not a normal debugger will do
    2. Use breakpoints to narrow down exactly where the problem occurs
  2. git bisect
    1. Identify exactly which change introduced the bug
      1. also reason why you should merge instead of rebase (^pzjio5)