DEV Community

Sadick
Sadick

Posted on

Debugging Tips

Programmers write code. Programmers aren't perfect. The programmer's code isn't perfect. It therefore doesn't work perfectly the first time. So we have bugs.

We should always employ sound engineering techniques that minimize the likelihood of unpleasant surprises.

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

Tips

  • Reduce bugs to the simplest set of reproduction steps possible.
  • Ensure that you are focusing on a single problem.
  • Assertions and logging (even the humble console.log) are potent debugging tools. Use them often.
  • Binary chop problem spaces to get results faster.
  • As you develop your software, invest time to write a suite of unit tests.
  • Untested code is a breeding ground for bugs. Tests are your bleach.
  • Learn how to use your debugger well. Then use it at the right times.
  • Fix bugs as soon as you can. Don't let them pile up until you're stuck in a code cesspit.

Debugging isn't easy. But it's our own fault. We wrote the bugs.

Discussion (0)