Advertisement

Dumbest coding mistakes ever

Started by February 07, 2012 01:19 AM
53 comments, last by Bacterius 12 years, 6 months ago

[quote name='AltarofScience' timestamp='1328635801' post='4910564']
I guess I am just a bizarre abberation. I write all my code with every line on the left edge

thing=0;
otherthing=10;
while(thing<otherthing) {
stuff;
stuff;
thing++;
}
more;
code;
all;
on;
the;
left;


spacing things out generally confuses the hell out of me too.

Yup, that's pretty weird. But there's no mistakes in teh codes....
[/quote]

I don't think its that wierd; I've seen code like this in C by a guy who had previously only worked in assembly language for some kind of PIC chips. He was writing very low level code, pretty much treating cc as a code generator. If I encountered code like this for high level operations though, i would very tempted to do a ^a ^k ^f...
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!
Test loop for testing the framerate system. Try to find out why the framerate system was always returning 2 frames instead of 1:
for (unsigned i = 0; i <= 300; i++)
i += update_program();

(update_program returns the number of ellapsed frames)
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
Advertisement
No examples, but that above example reminds me of so many times when using a nested loop that I used the wrong iterator value as an index. Especially with the whole i and j iterator idiom. I remember one time I read over the error for a whole day and it was like my brain had changed a j to an i and I just kept overlooking it. Wasn't going out of order. The numbers in the array were so arbitrary that debugging it didn't make me suspicious at all.

No examples, but that above example reminds me of so many times when using a nested loop that I used the wrong iterator value as an index. Especially with the whole i and j iterator idiom. I remember one time I read over the error for a whole day and it was like my brain had changed a j to an i and I just kept overlooking it. Wasn't going out of order. The numbers in the array were so arbitrary that debugging it didn't make me suspicious at all.

I think ive grown a seperate brain lobe just to reason about these type of situations. The kind of bugs used to be the bane of my existence as a young coder, but now I dont have to think about it anymore.
Just happened to me recently:


for(int i; i<N; i++) someArray = i;


Especially fun as it worked fine for days on my debugging machine but failed in obscure ways when run on the production cluster. I'm still wondering why gcc didn't throw a warning here...

No examples, but that above example reminds me of so many times when using a nested loop that I used the wrong iterator value as an index. Especially with the whole i and j iterator idiom. I remember one time I read over the error for a whole day and it was like my brain had changed a j to an i and I just kept overlooking it. Wasn't going out of order. The numbers in the array were so arbitrary that debugging it didn't make me suspicious at all.


As I often got confused by this i started to name my iterators with real variable names when ever there's more than one loop at a time. This helps me to not just parse-over all i and j and k or x and y and z and think they're the same.

single loops, i typically don't see them anymore (c#, linq), but when i use one, then i use the variable i. So it's clear to me, it's an ordinary, single loop. if it isn't, i change the name.
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Advertisement

single loops, i typically don't see them anymore (c#, linq), but when i use one, then i use the variable i.

This is actually one of the nice side benefits of using std algorithms + lambdas in C++11: you find yourself declaring variables named i much less often.
this one got me a few times:

point p = (10, 20);

instead of

point p(10, 20); or point p = point(10, 20);
No code example, but after doing a lot of C++, I switched back to Java for a small project.

I took copy constructors and sending objects as parameters for granted... it became really messy and difficult to track, and I kicked myself when I realised that I was sending object references all over the places, not copies.

I guess I had assumed that java would somehow have taken care of that?!
//Boolean logic Fail
if (DateTime.Now.DayOfWeek != DayOfWeek.Saturday || DateTime.Now.DayOfWeek != DayOfWeek.Sunday)
{
weekday = true
}
else
{
weekday = false;
}

This topic is closed to new replies.

Advertisement