When you fail so hard...

Here's one that will tickle the code geeks among you.

I was coding a program earlier that would basically loop through a mapping table, load up objects from a database, and save them to flat files in a physical drive. The program itself is nearly 500 lines long due to all of the comments and indentation that I put in- I may not be a good coder, but I am a thorough one.

So there I was, testing and debugging this script, and lo and behold, after the first couple of minor bug fixes, it worked exactly as I thought it would. The objects would be loaded; they would be renamed; they would be saved; and an automatic notification email would be sent out.

Except... even though the notification email said that all objects had been loaded and saved correctly, when I tried to load those very same objects from the locations that they were supposed to be in, they didn't exist.

I was stumped. Surely it was working correctly. I'd checked and double-checked and triple-checked the syntax- no problems there. The program compiled and ran just fine- no issues there either. The variables were all declared within the right lexical scopes- no cock-ups there.

I went away for a cup of tea, still scratching my head, trying to figure out just what the hell I'd done wrong. Still couldn't figure it out. Now, I've been in this situation before, and I've found that the best way to deal with it is to go do something else for a while and then come back and look at the problem again with fresh eyes.

Which, of course, is precisely what I did. I went and goofed off for a while. And if you're a programmer, you know exactly which excuse to use when your boss comes over and asks why you're checking out women in lingerie at the Daily Mail re-watching videos of Holly Holm's epic knockout victory over Ronda Rousey looking at pictures of dogs playing with tigers:

Then I finally quit goofing off, sat down, and immediately got that horrible sinking feeling you get in the pit of your stomach when you realise you've done something so abominably, galactically, cataclysmically stupid that you just know that people will someday create monuments to your idiocy for the specific purpose of hurling rotten fruit and other more odious things at them.

I went back and looked at the subfunction designed to loop through the list of available drives and figure out what went where. And there it was, plain as day: I'd hardcoded the integer "1" as the value returned by the loop.

In other words, for every object that I was trying to load and save, the program would simply save down everything to the second drive in the list. (Indexing in C++ and similar languages starts at 0 by default, not 1.)

Head, meet keyboard.

Several repetitions of this introduction later, with my forehead considerably flatter and my head hurting rather a lot, and after more than a few alarmed looks from my co-workers, I fixed the bug and unFUBARd my program. And, lo and behold! It functioned as expected at long last.

And that, ladies and gentlemen, is why you should NEVER put a programmer in charge of your nuclear missile defense systems. You might discover just a moment too late that there's a bug in the code somewhere...


  1. Replies
    1. Nothing better than a well-timed WarGames reference =)

  2. As a fellow programmer I know that feeling all too well...


Post a Comment

NO ANONYMOUS COMMENTS. Anonymous comments will be deleted.

Popular Posts