DEV Community

Discussion on: What do you do when you encounter a hard to fix bug?

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

Ha! I've done all of these. Nice list. You should think about writing a full article to this effect. :3

Here's a few more things I do.

  • Literally print the source code out on paper! I am dead serious. Sometimes my eyes get so tired of reading on the computer (and, honestly, that's true of many of us whether we admit it or not). By switching to the more comfortable paper-and-ink medium, I am sometimes able to see things I missed.

(Incidentally, I also sometimes print source when I'm reading particularly complex source written by other people.)

  • Desk check! Get out a piece of paper and become the compiler. Start reading through the source code exactly as the computer would. Resist the urge to skip forward. Take nothing for granted. Write down each variable name, type, and value, and change it exactly as instructed by the code. 9 times out of 10, this allows me to catch the error.

  • Break out the LEGOs. Sometimes a paper-based desk check isn't enough. For particularly complex algorithms, I'll use my LEGOs and other desk toys to fill in for certain code structures, elements, pointers, objects, etc. There's no rules to this: just do something that makes sense. This is especially helpful when debugging search and sort algorithms. Besides that, it's fun.

--

I have to emphasize one of the points already made: talk to a non-coder. My mother, who is also my business partner, knows just enough about programming to help oversee project operations, but she isn't a coder by any means. On one occasion, after three days of my trying to debug something, she walked in and said "I bet you forgot a semicolon".

Yup. I'd forgotten a semicolon - right in the middle of a for-loop definition - thereby creating an infinite loop.

Collapse
 
alephnaught2tog profile image
Max Cerrina

Thanks! :D I really like the idea of printing it out. I always forget about paper...