Debug like a detective

One of my favorite things about writing code is debugging. Yeah, I know what you’re thinking. Insanity! It’s much more fun to write buggy code than to unravel it! But problem-solving is fun. It’s why I became a developer in the first place. After a lot of menial labor type work I was bored and wanted to use my brain. Plus, I get to pretend I’m a detective!

As a software developer, only part of your day is always devoted to writing code. Often the lion’s share of your time is spent solving the bugs you’ve written (if you’re lucky) or those you didn’t (if you’re most of us) or reading through code others have written helping them avoid bugs.

You could look on this exercise as a dull task that must be executed and find no joy in it. But let me tell you, Gentle Reader, it’s still far more entertaining than scrubbing toilets, waiting tables, or making lattes for a living.

Debugging is kind of like a classic mystery storyline. A crime is discovered. Tension builds. The detective has a hunch but can’t quite put it all together. The prospect of losing one’s badge, personal relationship, or even life do not deter the detective one bit! She has a curiosity itch that must be scratched. A sleuth will find answers, no matter the cost. The resolution is its own reward.

While developing my debugging skills, I’ve discovered a few good tricks along the way. It’s important to develop a well-honed use of the tools of the trade before wandering into dangerous situations.

How I like to imagine myself sleuthing
probably closer to the truth…
  1. First off try to describe the bug out loud. If you have a rubber ducky handy, tell him what is wrong and I promise he will listen without interrupting. Part of the way through you may already have a eureka moment. If not, feel free to talk to another human being. Talking to a duck or anyone, really, forces you to use a different part of your brain.

As a side note, it’s good practice to reformat your hard drive every few years or so. Upgrade to the latest OS & reinstall everything. You will find you may not even need an upgraded machine after a few years. This works like a charm and will keep your wallet happy! Plus, fewer old laptops for the trash heaps.

I hope this helps! Please feel free to share your favorite debugging tips with me in the comments!

Thoughts on code, climbing, and DIY. JavaScript, Elixir, and other fun stuff.