Stupid Programmer Tricks
I was going to reply in the thread, but I thought this might actually be more entertaining...
Phantom made a comment to me in another thread (which I understood was a joke by the way, even before you told me it was!) and it got me thinking... what's that absolute stupidest mistake I've ever made in programming?
We've all made 'em. You know, the things where when you finally get the answer you yell out "How the HELL did I miss THAT for EIGHT HOURS?!?". Or the ones that when you finally figure it out make you so embarrassed that you look for the nearest tall building to throw yourself off of?
If you claim to never have made a stupid programming mistake, you have NEVER PROGRAMMED!
So, why not have some fun with it? Why not tell the world (such as it is in ONE forum on ONE web site!) how dumb you can really be sometimes... tell us the stupidest programming mistake you've ever made!
I'll start off...
Back in about '86 when all I did was code assembly day and night on my trusty C64, I had this one demo that kept crashing hard on me every time it came to this one chunk of code. Well, I narrowed it down to no more than 20 lines of code, and I then sat staring at it for no less then three days. Couldn't find the problem no matter what I tried.
What did it finally turn out to be?
There was an opcode called LDX, load the X register. Well, I had LDY, also a valid opcode, but quit a bit different.
Need I say more?
So come on guys, throw 'em out there! Let us all have a good laugh at your expense!
You know that lovely little ; required at the end of classes, structs, and enums?
when I was first learning C++ I was writing this huge class late at night and forgot all about the semicolon. Then proceeded to spend 5 hours trying to figure out what the compiler's error message meant.
You made me think of a general thing that happens to this day, I'm sure to all of us...
Don't you just love when you forget a semicolon, or worse yet, a closing brace? I love when I get 300 or so compiler errors that can be fixed by adding ONE SINGLE CHARACTER (of course, it's usually closing a block of code 4,000 lines back, so actually figuring out where to place it is a nightmare... yes, I know, IDE's will tell you, blah!)
Of course, when my boss asks me what I did today, I can tell him "I squashed 300 bugs!" (which took 30 seconds, then spent the rest of the day surfing the web).
Back in college I was up late working on a class project. Basically we had to process a set of strings and produce various output.
We had to write a strcpy function in C using only pointers and after 3 hours of crashes and headaches what did I forget? All together now, "Null terminate the string!"
It's like locking your keys in your car. You do it once, then never again.
Pam
I've locked my keys in my car more than once.
(Oops, did I just type that?)
Worse yet, I locked them in my HOUSE. Breaking into your own house is not fun, especially when you have an alarm system.
I should add this one too...
A couple of months ago I was working on a message board system done in Active Server Pages, ADO to a SQL Server database. Well, I called up the page to display the list of forums, and the server seized up harder than a '68 Dodge with no oil in the pan.
What did I do wrong?
Gee, you know when you do something like:
Do While Not objRS.EOF
Loop
And your iterating through the result set?
Lemme put it this way: it's always a good idea to move to the NEXT RECORD!
(Man I hate infinite loops)
I had a problem that I had been working on for my own interest when I was first teaching myself C++. I developed a templated class for the problem because it was a large numerical problem, and could conceivably need larger-than-64-bit integers later in the game.
Well, my class had some stupid little bug in the code to travel and operate on a binary tree. I can no longer remember the exact bug, but it seemed straightforward enough at the time. I fixed it, recompiled, and the same bug popped up. I thought, "Well, there must be a different bug somewhere else in the code." I looked around, found a few bugs here and there, but nothing that would fix the problem. I spent few days working on it, then finally gave up, since it was just for my own interest and I had more important things to spend my time on.
A year or so later, I looked back at the program. The bug still didn't make any sense, so I spent some more time stepping through the code. Eventually, I noticed that the debugging code I had put in wasn't running--I would create a variable, increment it, and the variable never seemed to exist. Finally, I came to the conclusion that the code I was looking at was not the code in the program. It turned out that Visual C++ 4.0 had a bug in it that would ignore changes to template class files, so after any changes, you needed to use the "clean" command before recompiling.
Since then, the first thing I do whenever there's a difficult bug is just recompile my whole program. It continues to save me hours of problems to this day, even with the most current compilers.
-Ionitor
Haha, I love ASP. "We'll just add this simple bit of code here and now lets see how this runs..." 10 minutes later. "Ooops, locked up the server again"
Ionitor: I've run into a bunch of bugs like that. I too immediately rebuild the whole project alot.
Here's another one. When dealing with RECTS getting the width and calculating it as left - right instead of right - left .
"Why's my blit failing?"
I do this ALL the damn time.
Wow. I haven't the time, nor has the server the HDD space, for me to start listing all of my stupid mistakes.

I've already posted my most recent (where I chose a name for a new function and used it for the declaration and call, and then used a different name for the implementation. I scratched my head for 15 minutes wondering why the linker couldn't resolve that function, and started playing around with the calling convention before I figured out my stupid mistake).
A student at YSU made the typical newbie mistake of reversing the last two parameters of a for statement. She worked on it all day trying to figure out what was wrong with her code (on a Unix workstation, so no interactive debugging was available). I only had to glance at it to see that glaring mistake.

To this day I make a comment like "//This is not a mistake" when I do "abnormal" things in for loops.
Dan East
I wrote a "clearscreen" function once for DOS. Every time I tested it on its own, it worked a treat. Every time I tested it in the application it hung and dropped dead. Turned out that calling my test application "CLS.exe" wasn't such a good idea
When I worked in London there was somebody (not me!) that did:
update customer set surname="Smith";
and ran it by mistake (forgetting the where clause)... and consequently changing the surname of 20,000 people to "Smith"
Luckily we could feed all the data back in from the mainframe, but it caused a bit of a panic

heh, I've made so many programming mistakes it would take me all day to come up with only a fraction of them. On the plus-sideI've become a pretty routined debugger by now
most recent one I can come up with is an ActionScript I had programmed for work (meh, it's not even a real programming language

). ne ways another programmer made some minor changes to it, and it mysteriously stopped working. It was a game and it wouldn't save the scores anymore. After 5 hours of debugging i was literally banging my head against the wall. So I decided to rtfm, and it just said "you can't write to files anymore, if you want to... you're pretty much screwed"
So instead of publishing it with FlashMX, I published it in Flash5 (in which I had written it originally) and everything was working fine.
Well, nothing big here since I don't have that much experience with programming.
However, I made a guestbook in PHP that should store the entries in a simple encrypted .TXT file instead of a SQL database.
I uploaded the script on my temporary PHP webspace, typed in the URL of the "view guestbook" page and left the room, thinking about having lunch or something.
When I came back, the whole screen was filled with PHP error messages, the output file had a size of several MB.
What happened:
The "add entry" page was supposed to create the .TXT database, the "view guestbook" page should either read the database and create a table structure or write something like "guestbook empty" if the database didn't exist or was empty. However, for debugging purposes I had removed the part which was supposed to check for the existence of the database, so the script created the whole table structure again and again, filled with error messages.
PHP scripts are limited to 30 seconds of execution time (obviously because of guys like me

), but it was time enough to torture the server quite a bit.

Fencepost error...
Or maybe it was when I was first playing around with HPC Quake and I was trying to inialise GameX. In the documentation it said:
GameX gx = new GameX;
I assumed he forgotten the comment and I thought it should have said:
GameX gx; //new GameX
So I couldn't figure out why I was getting crashes...
Doohhhhh!!!!
Usually for me I make stupid naming errors:
- Code:
.
self.movedDragBoxYet = True
.
.
later
.
.
.
if self.movedDragBox == False:
I kept wondering why self.movedDragBox was false when I just set it to true a while back..
Rule: don't put on suffixes or prefixes you are likely to forget

Though i'm still a newbie when it comes to C++ (i still haven't done anything involving the Win32 API, i'm still doing console apps), my achilles heel is the boolean ==. I often only use a single = and end up in infinite loops...
Come on, the classic would have to be putting a single = in an IF statement.....
if(a = b)....
I've done that a few times, wondering what the hells going on when my code starts doing wierd things... makes it worse whne you "link" the problem to another section of code.... and start debugging....
A trick to keep from doing that is to always place the constants first. So if you're checking if something is zero you do if( 0 == blah ) instead of if( blah == 0 ). That way when ever you forget that extra = it becomes a compiler error and VERY easy to find
Course, doesn't work when you're comparing to vars

...thats a good idea. Almost as good as that x=1-x to toggle a number.
Hosed wrote:
A trick to keep from doing that is to always place the constants first. So if you're checking if something is zero you do if( 0 == blah ) instead of if( blah == 0 ).
hehe, seems a bit useless, if you can remember to put the constants first you might as well just remember to put in a ==
but hey if it works for you

The single = is far harder to spot and infact can happen to easily during late night bouts of coding. I found when I used to run into this error a lot that it was always because I thought I had two, but didn't get the two in. Howeber, if you can't remember to even put 2 equals on checks then frankly you shouldn't be programming.
Try it. If you get these kinds of bugs a lot you'll find after a month you never get them again.
it's just one of those typical mistakes programmers new to C++ or Java tend to make. just like using == (or even =) instead of .equals to compare two objects in java. But the one that gets noobs really bouncing off the wall ofcourse is... null pointers!!!

BurningSheep wrote:
it's just one of those typical mistakes programmers new to C++ or Java tend to make. just like using == (or even =) instead of .equals to compare two objects in java. But the one that gets noobs really bouncing off the wall ofcourse is... null pointers!!! :)
== is (generally) less of an issue in Java because it has to be a boolean expression (not the fun that you can do in C(++) where anything is a boolean (As long as it's not zero). Of course, the .equals thing is a pain.
The most recent and most stupid thing I did was something like the following.
for (jclass tmp = klass ; tmp ; tmp = klass->getSuperclass() )
- and it worked for simple cases as well, which meant I didn't notice it. Thank god for test suites ;>
I had much fun for some time with a piece of code like that:
- Code:
if(a==b);
{
//some instructions
}
for some strange reason, the condition seemed to be always true

See Quirk, now that's a great one! I actually stared at that for a couple of minutes going "Why is that a problem?".. then it hit me. DOH!
This is true.
I spent hours on the Atari ST writing the fastest disk formatter I could. When I got it compiling, I ran it. It formatted the my *source code* disk, and then crashed. Always whip your source disk out when writing a disk formatter.

I wrote a very evil DeleteDir routine to iterate and delete an entire directory tree. The first time I ran it I should have just dumped the name of the file it would delete, instead of actually performing the deletion. I wiped out an entire drive because I didn't realize that FindFirstFile would iterate the "." and ".." directories as well, so it iterated the entire directory structure of the drive. Oops.
When I was at YSU we had to write a program to run on a Unix box that would fork to create a duplicate process. I performed a typical newbie mistake and the thing forked out of control. Soon the unix box didn't have any free processes - my program was sucking them up as fast as they became available. So I quickly wrote a shell script that would hunt and delete those processes. It ran for several minutes until it finally caught up to the lead process that was about to fork and killed it.
Dan East
Hey, theres nothing wrong with almost bringing a college UNIX box to a halt....
(where I went to uni, it was common to not allow forking on std user accounts.....), for some reason it "seems" like a good type of program to write, "just to see what will happen".... not that I ever did!
-B
I had much fun latelly with something like this:
- Code:
TUint32 animationtime;
...
TUint16 animationendtime;
...
animationtime=GetTickCount();
animationendtime=GetTickCount()+animlength;
and while performing an animation
...
if (animationtime>animationendtime)
{
animationtime=animationendtime;//we make sure we don't go too far
}
that was fun...

hehe, nice one
ok, i was going through some code that apparently wasn't working.
after removing a _shitload_ of commented out code I found this:
- Code:
if(bSomething == true)
{
FunkyFunction();
}
else
{
FunkyFunction(); // yeah that's right, same funky function ;)
}
I swear I didn't write this!!! ;)
neways that wasn't the problem since that part worked fine, the 'if' just became completely unnessecary after a lot of modifications...

I would imagine a good optimizer would catch that. It would be fun to write a compiler someday. I can see some possible warning messages for that one:
error C3153: Software Developer requires sleep
fatal error C2850: Software Developer responsible for this line of code is an idiot
warning C3910: Why are you compiling software at 3 AM?
error C2501: Exceeded 10,000 lines of code without encountering a single comment.
fatal error C4010: An unknown syntax error was encountered between lines 5 and 2751
Dan East
C4010... THAT'S a riot!
As someone who actually has written a compiler (years ago in Compiler Construction class), it IS a lot of fun. Modern compilers amaze the hell out of me though, I wouldn't know where to start any more.
>warning C3910: Why are you compiling software at 3 AM?
#pragma warning (disable:3910)

Warning C5678: It appears you’re trying to create another tetris clone, compile halted!
-we can wish.......
i didn't do this , but i was the one that found it and beat the programmer to death afterwards
assert( InitGame() );
assert( LoadAssets() );
assert( lots more of these );
now this worked fine in our debug build ,
BUT in final release build when we remove asserts
#define assert()
The above line just doesn't get compiled in !!
also this was 2 days before final submission to sony
when we added this guys code into the full product
( he was designing mini games )
- deadsoul
Somebody who worked for the place I work now had an obsession with timer events. The entire GUI handling was based around a timer on each window that would fire every second. It was complete, utter, total madness.
The lamest programmer I've ever seen/suffered just couldn't code *anything* properly, and he was the "most qualified" person that was interviewed. If we find bugs now, we try and locate the problem by searching for comments in French (we all write in English - he wrote in French)... rather sadly it's actually pretty good way of finding bugs. He's gone now too, thankfully.
Another amusing one was an "Access" "programmer", who regularly had the Access manual open on the "IF" page - it took her ages to work that one out.
Ho hum.
Cheers,
Reefractor
I can't remember any stupid programming mistakes I made...
But I can remember another stupid mistake:
I was testing some network 'stuff'... and forgot to plugin the (utp) netwerk cable :)
Doh !
my favorite : lost perhaps 1 week tracking the memory leak in this code
- Code:
if (someFlag) {
*insert 40 tabs due to a weird copy & paste operation before* return;
free(someMemory);
}
// some useless code
return;
Morals : use an editor that isn't scrolling or at least is checking too long lines

Here's another case of
- Code:
while (iCount < SomeNumber)
{
//here's the code that does some stuff
//to an array
}
hmmm... why did my program stop responding?
Crap, I forgot to increment the iCount variable. That's why it's not good to stay up too late coding.
here another funny incremental mistake i've done.
thanks to the copy/paste:
- Code:
for (int i = 0; i < val1; i++)
{
for (int j = 0; j < val2_that_the_name_is_long; i++)
{
//code here
}
}
A work colleague asked me to knock up a quick DOS utility to recursively delete a sub directory.... (you know whats coming don't you!!)... I forgot to tell it to stop when it recursed back to the original directory and I managed to wipe his whole hard drive in just a little over 20 seconds. That's quite an impressive speed don't you think. This was a few years ago mind when hard disks weren't that big.

A work colleague asked me to knock up a quick DOS utility to recursively delete a sub...
DING!!!
Wow, it's Deja Vu all over again!
Here is another one of my favorites:
- Code:
unsigned short x;
for(x=100; x>=0; x--)
{
//do something
}
regards
Quirk
Hey, seeing these I can remember some stupid mistakes.
- Code:
// some pascal stuff
var
something : word;
begin
something := 0;
// this loop will run 65535 times, woeps.
for i:=0 to something-1 do
begin
end;
// using loop variable for something else in a
// loop or weird stuff like that.
// I never really found what was causing my
// little '3d engine' to crash like that.
// but somehow the i variable went beyond the loop.
for i:=0 to 2 do
begin
i := 7; // stupid !?
// ???
end;
end;
>A work colleague asked me to knock up a quick DOS utility to recursively delete a sub directory.... (you know whats coming don't you!!)... I forgot to tell it to stop when it recursed back to the original directory and I managed to wipe his whole hard drive in just a little over 20 seconds. That's quite an impressive speed don't you think. This was a few years ago mind when hard disks weren't that big.
Heh, if we are talking about cock-ups, I have a great one: on my second day at my first programming job when I was about 16 or 17 I was asked to write a program to test the disk compression software (back in Windows 3.1 and DOS days, Windows 95 was just coming out) by writing out a string to disk thousands of times. They suggested I use my name as the string.
Anyway I set the program running on a large file size and then realised I'd put far too many zeros in the size (so I'd done about 100000 instead of 1000). I got a calculator and worked out how long it was going to take, and it was going to take a few hours, so went "damn" and decided to quit the program. Escept of course this was before PCs had multi-tasking. So I hit Control-C, Control-Break and even Ctrl-Alt-Delete. No luck. Then I hit the reset switch, and when the computer booted up it found itself completely dead. Oh dear. This is my second day on the job remember...
Several hours, and a few Norton Utilities later (of course I didn't know what Norton Utils was back then, but I do now), one of the other programmers was looking over the partition table and found that (wait for it) I had managed to write my name all over the partition table (and presumably the rest of the disk as well).
I had a slightly red face.
Weird thing is, I still seven years later have no idea how it could have happened... as far as I'm aware when using standard Microsoft C C-Library functions most FAT systems do not start writing on the partition table after they fill up! (At least I hope not otherwise I'm installing Linux!)
Maybe it was dodgy disk compression software!
Maybe it was dodgy disk compression software!
If it wrote your name over the partition table
without compressing it, then yeah, I'd call that dodgy

(even dodgier than writing over the partition table in the first place).
Lots of my first "commercially" written programs were in Q-Basic (in DOS), where I got up to all sorts of very naughty tricks, like switching screen-modes, and writing straight into the character screen memory

to implement nice looking menus with DOS characters... yucky.
DEF SEG=HB800 , IIRC
Cheers,
Ref.
Yeah, QBasic was fun, don't get me wrong, back then I wasn't the l33t h4x0r d00d that I am right now *cough*
But I distinctly remember writing some serious kickass Hello World-apps with it. Maybe I should look the stuff up sometime, it's bound to have all kinds of crazy programming mistakes

Heh.. I used to have soooo much fun with qbasic when I was nine or ten. I'd write a program to draw my name on the screen, and then it would set the pallette to all fire colors. Then I had some cheap blurring algorithim; it would take maybe 5-10 seconds to complete each pass! Each time my name would get bigger and glow... ah it was cool
