Debugging

From ProgClub
Jump to: navigation, search

The plan with this page is to build a checklist for potential causes of bugs. I'm annoyed that I only started this 30 years after I started programming. Every time I solve a problem caused by a type of bug I will try to add it to this list so it doesn't get me so easily next time.

Checklist

Some questions to ask yourself when you're debugging a problem:

  • are your inputs valid? i.e. valid format, valid range, etc. if you're looking at code which you swear is correct then the problem is probably in your inputs.
  • have you used an 'if' statement where you need a 'while', or vice versa?
  • have you used a 'foreach' statement where you need a 'for', or vice versa?
  • have you made an assignment (=) instead of an expression (==)?
  • did you forget to call your parent's constructor?
  • did you pass a constant value instead of a constant name to e.g. defined()
  • have you changed a positional interface (function parameters in order) without updating callers? positional interfaces are typically used in DAL add() and set() functions. as a general rule you should only add parameters and never change their order.
  • are you in the right directory?
  • did you actually assign the values in the constructor? (Make sure there's a field, then an equals sign, then the value, and not that you've forgotten the equals sign and value.)
  • are all the executables in the $PATH?
  • in some languages all([]) will return true, so make sure you get what you're expecting if you pass an empty list
  • is it plugged into the right socket?
  • in your shell script does your line end with ':' instead of ';'?
  • have you called a PHP function such as `var_dump` with input that contains circular references?
  • have you run out of disk space?
    • if a reboot fixed the problem check for space in /dev/shm and /tmp

Taboo

These are things you shouldn't do...

  • don't modify the list you are iterating over (make a new list instead)

Reference