Down the wrong path

I've been chasing a bug for 2 days and it turns out to be one of those flat-forehead mistakes where, once discovered, you slam the heel of your hand into your forehead.

Long story short, a for loop was used to draw an analog meter face with a scale that ran from 0 to 100. It ran fine until the loop was drawing the endpoint of the scale. I put in a bunch of debug statements to try and track the bug down...everything from simple variable prints to free RAM macro. What was worse, if I commented out a specific Serial.print() debug line, it worked fine. If I put that line back in, it locked up.

With much less hair than when I started and a much flatter forehead, I noticed that, while the range was from 0 to 100, I later added a +sign to the numbers. Only after 2 days did I remember that the buffer used for the itoa() function was defined with 4 bytes. When the value within the loop reached "+100", kaboom!

The lesson: if debug statements seem to "fix" things, make sure you're not overflowing a buffer somewhere.

These bugs are known as "wheel-tappers", after the steam-age guy who tapped railway stock wheels with a small hammer to see if they rang, or were dull, indicating a crack.
This particular guy sent sixteen locos to the repair sheds before it was discovered that it was his hammer that had the crack . . .

AWOL:
These bugs are known as "wheel-tappers", after the steam-age guy who tapped railway stock wheels with a small hammer to see if they rang, or were dull, indicating a crack.
This particular guy sent sixteen locos to the repair sheds before it was discovered that it was his hammer that had the crack . . .

:slight_smile: I very much enjoyed this.

AWOL:
These bugs are known as "wheel-tappers", after the steam-age guy who tapped railway stock wheels with a small hammer to see if they rang, or were dull, indicating a crack.
This particular guy sent sixteen locos to the repair sheds before it was discovered that it was his hammer that had the crack . . .

Hadn't heard that story.

To help with these kinds of bugs, you need a test teddy.

Get yourself a teddy-bear, or some other plush toy: a unicorn, a cthulhu. Whatever you can relate to. When you have been struggling with a bug for a while and getting nowhere, ask your test teddy to help. You'll have to start by explaining to the toy how your code works. Step the bear through your code verbally.

It's amazing how often the bear will catch the bug.

I used to have my own software company and when a bug like this happened, I just called over another set of eyes to look at the code. Usually even the most obstinate bug would reveal itself in minutes. Now that I'm retired, it's just me.

I'm on the lookout for a teddy bear.

If one is available, a patient spouse is a good substitute for a test teddy. (Having such a spouse who also develops software is a godsend.)

Actually, a great idea, but I know that's not gonna happen. For years she' been trying to understand why I enjoy software development. I've seen a few teddy bears on eBay...

I'd go for a chameleon rather than a teddy, then it can catch the bugs while you go for a walk.

Talking of, that helps too sometimes. I recall a few times as a student I'd walk round the block while mentally grappling with some structural design assignment.

And I was once on a course with a software developer who said he often charged off down the road in town with his pad in hand to get his mind off the problem he was stuck with. When the answer revealed itself to his subconscious he noted it on his pad, then made a "u" and back to the office.

ardy_guy:
I'd go for a chameleon rather than a teddy, then it can catch the bugs while you go for a walk.

Talking of, that helps too sometimes. I recall a few times as a student I'd walk round the block while mentally grappling with some structural design assignment.

And I was once on a course with a software developer who said he often charged off down the road in town with his pad in hand to get his mind off the problem he was stuck with. When the answer revealed itself to his subconscious he noted it on his pad, then made a "u" and back to the office.

I got my ham radio license in 1954 and have been licensed ever since. Back in HS, my football coach asked me to assemble two Heathkit walkie talkies. I put them together and they didn't work. I tried for days to figure out what was wrong. One morning my Mom told me I had gotten up in the middle of the night and wrote something on the pad next to the phone. I read it, went to my shack, and fixed the problem in about two minutes.

Ever since then, I keep a pen and pad on my night stand. I can't even count the number of things, ideas, teaching examples, etc. that ended up on that pad and I rarely have any recollection of writing them down. The mind is an amazing piece of equipment.