Advertisement

Dumbest coding mistakes ever

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

Why would it fail? Wouldn't it just do nothing? Or is it because v.size()-1 presumably is unsigned since it's being compared against a size_t so it would run MAX_INT times?

Because size() returns a size_t, which is unsigned. And (unsigned)-1 is a very, very large number...

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

The first one is an uint16, which presumably, a 16-bit integer whose maximum value is 65536. That loop iterates 70000 times.

The second one is the conditional i < size()-1. The last element won't get counted for. And of course, if size() returns 0, it will evaluate to a very large number.
Advertisement
How is this for a brain dead mostly asleep error?

Trying to work on something while way past too tired to program, but I needed to get something done that I could actually show someone.

started with for x in a:
for y in a:
# Do something with x[0] ... y[1]
#A short time later...
for x in a:
#Do something else x[0] .... y[1]


Also managed to screw myself over trying to hunt down a bug over position 1 vs 0 of a list. Translating some notes written by someone else into code can be dangerous. The issue was so hard to track because for most of the data set had the same value in the first two elements of the list, except for a few rare cases.
Old Username: Talroth
If your signature on a web forum takes up more space than your average post, then you are doing things wrong.

if(x % 1 === 0)


I did this a few nights back, I was up really late playign around with JavaScript and the Canvas HTML Element and for some reason needed to test if something was odd or even...

This is obviously not how you do it.
Mark A. Drake
OnSlaught Games
Mark Drake

function Vector(const X, Y, Z: Double): TVector;
begin
Result := Vector(X, Y, Z);
end;


It just seemed logical at the time I wrote this mellow.png

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

This topic is closed to new replies.

Advertisement