Jump to content



Dumbest coding mistakes ever

  • You cannot reply to this topic
54 replies to this topic

#21 speciesUnknown   Members   -  Reputation: 531

Posted 07 February 2012 - 07:56 PM

View PostCornstalks, on 07 February 2012 - 11:33 AM, said:

View PostAltarofScience, on 07 February 2012 - 11:30 AM, said:

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....

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!

Ad:

#22 Sik_the_hedgehog   Members   -  Reputation: 235

Posted 08 February 2012 - 01:07 AM

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.

#23 Sirisian   Members   -  Reputation: 992

Posted 08 February 2012 - 01:10 AM

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.

#24 Eelco   Members   -  Reputation: 163

Posted 08 February 2012 - 02:25 AM

View PostSirisian, on 08 February 2012 - 01:10 AM, said:

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.

#25 Phobon   Members   -  Reputation: 157

Posted 08 February 2012 - 09:53 AM

Just happened to me recently:

for(int i; i<N; i++) someArray[i] = 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...

#26 davepermen   Members   -  Reputation: 670

Posted 09 February 2012 - 04:53 AM

View PostSirisian, on 08 February 2012 - 01:10 AM, said:

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


#27 jwezorek   GDNet+   -  Reputation: 275

Posted 09 February 2012 - 11:38 AM

View Postdavepermen, on 09 February 2012 - 04:53 AM, said:

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.

#28 froop   Members   -  Reputation: 160

Posted 09 February 2012 - 12:23 PM

this one got me a few times:

point p = (10, 20);

instead of

point p(10, 20);
or
point p = point(10, 20);


#29 J-dog   Members   -  Reputation: 116

Posted 10 February 2012 - 01:59 AM

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?!

#30 Instigator   Members   -  Reputation: 98

Posted 11 February 2012 - 01:52 PM

//Boolean logic Fail
if (DateTime.Now.DayOfWeek != DayOfWeek.Saturday || DateTime.Now.DayOfWeek != DayOfWeek.Sunday)
			{
				weekday = true
			}
			else
			{
				weekday = false;
			}


#31 Alpha_ProgDes   GDNet+   -  Reputation: 1299

Posted 11 February 2012 - 03:02 PM

View PostInstigator, on 11 February 2012 - 01:52 PM, said:

//Boolean logic Fail
if (DateTime.Now.DayOfWeek != DayOfWeek.Saturday || DateTime.Now.DayOfWeek != DayOfWeek.Sunday)
			{
				weekday = true
			}
			else
			{
				weekday = false;
			}

I did something very similar with SQL:

select dept, job
from organizations
where (dept = 'Marketing' and job <> 'Sam Wise')
or    (dept = 'Marketing' and job <> 'The Precious')




Note: Shout out to the GD.Net crew who got the keywords to automagically highlight properly without having to declare what language you're using. Impressive!
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts :)

Spoiler

#32 Cornstalks   Members   -  Reputation: 1216

Posted 11 February 2012 - 03:10 PM

View PostAlpha_ProgDes, on 11 February 2012 - 03:02 PM, said:

Note: Shout out to the GD.Net crew who got the keywords to automagically highlight properly without having to declare what language you're using. Impressive!
Side note: they use this guy.
[ Realistic Rendering ] [ School + Dublin = Boom ] [ I've been ninja'd 70 times ] [ f.k.a. MikeTacular ] [ My Blog ]

#33 Sik_the_hedgehog   Members   -  Reputation: 235

Posted 11 February 2012 - 03:53 PM

View PostInstigator, on 11 February 2012 - 01:52 PM, said:

//Boolean logic Fail
if (DateTime.Now.DayOfWeek != DayOfWeek.Saturday || DateTime.Now.DayOfWeek != DayOfWeek.Sunday)
			{
				weekday = true
			}
			else
			{
				weekday = false;
			}
Nonononono, you don't get it, that isn't boolean logic fail, that's company manager boolean logic (especially true in crunch mode!).
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.

#34 shurcool   Members   -  Reputation: 311

Posted 14 February 2012 - 11:19 PM

Just today I wrote:
auto TemporaryHeart = MoveHeart(State[8], State[10]);
MoveHeart(TemporaryHeart, State[12]);
MoveHeart(TemporaryHeart, State[3]);
MoveHeart(TemporaryHeart, State[8]);
TemporaryHeart = MoveHeart(State[9], State[11]);
MoveHeart(TemporaryHeart, State[13]);
MoveHeart(TemporaryHeart, State[2]);
MoveHeart(TemporaryHeart, State[9]);
Instead of:
auto TemporaryHeart = MoveHeart(State[8], State[10]);
TemporaryHeart = MoveHeart(TemporaryHeart, State[12]);
TemporaryHeart = MoveHeart(TemporaryHeart, State[3]);
TemporaryHeart = MoveHeart(TemporaryHeart, State[8]);
TemporaryHeart = MoveHeart(State[9], State[11]);
TemporaryHeart = MoveHeart(TemporaryHeart, State[13]);
TemporaryHeart = MoveHeart(TemporaryHeart, State[2]);
TemporaryHeart = MoveHeart(TemporaryHeart, State[9]);


#35 NickGomes   Members   -  Reputation: 112

Posted 20 February 2012 - 10:48 AM

I had one mistake that was just so dumb that I overlooked it. The functions worked independently but when i tried using them together...

void function1(Blah whatever)
{

	 //Tons of code
	 for(int i=0; i;whatever.count; i ++)
	 {
	   //tons of code
	   function2(whatever);
	   //tons of code
	 }
	 //more code
}



void function2(Blah& whatever)
{
	 //lots of code that does stuff
	 Blah whatever2 = new Blah();
	 whatever.count ++;
	 //more codes
}


I seem to always mess up iterators in functions.

#36 Mussi   GDNet+   -  Reputation: 231

Posted 20 February 2012 - 11:16 AM

Made this mistake a few times, very hard to spot in some situations.
for(int i=0; i < i_max; i++)
{
    for(int j=0; j < j_max; i++)
        array[i][j];
}


#37 tstrimple   Members   -  Reputation: 1087

Posted 20 February 2012 - 12:09 PM

Sounds like for the most part most people here would benefit tremendously from better tools. I haven't been hung up on anything like this for a couple years now. Check out the video showing how most of these types of problems can be avoided using good tools. It's not going to help most of the logical problems, but it does a fantastic job of helping you avoid silly errors like where a semi-colon is placed.

http://screencast.com/t/U9s4FW1HM9su

#38 way2lazy2care   Members   -  Reputation: 257

Posted 20 February 2012 - 12:33 PM

Today I forgot to compile something after making changes that should have totally changed the behavior of something and it took me a few minutes to realize why the behavior wasn't changing at all.

/monday

#39 rip-off   Moderators   -  Reputation: 2481

Posted 20 February 2012 - 03:46 PM

View Postway2lazy2care, on 20 February 2012 - 12:33 PM, said:

Today I forgot to compile something after making changes that should have totally changed the behavior of something and it took me a few minutes to realize why the behavior wasn't changing at all.

/monday
This happens to me sometimes when I'm working with our branch and trunk at around the same time. It can drive you crazy!

#40 Sik_the_hedgehog   Members   -  Reputation: 235

Posted 20 February 2012 - 07:39 PM

View Postway2lazy2care, on 20 February 2012 - 12:33 PM, said:

Today I forgot to compile something after making changes that should have totally changed the behavior of something and it took me a few minutes to realize why the behavior wasn't changing at all.

/monday
Reminds me of when I made a quick fork of a game to add time attack for a special event. No matter how hard I tried my attempts at resetting the timer would not work no matter what, it was like it was completely ignoring the code I was writing. Turns out I was editing the original file, not the one from the fork *facepalm*
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.






We are working on generating results for this topic
PARTNERS