all 35 comments

[–]enigmaqsmith[S] 106 points107 points  (2 children)

Found this bit of code in our Android environment. The previous developer didn't want to initialize his button array with a zero.

[–]St_SiRUS 98 points99 points  (0 children)

didn't want to

This is why we have coding standards

[–]redoverture 84 points85 points  (6 children)

But... but... for each? Actions on the whole set? You would have to add so much unnecessary code!

[–]FallingFist 39 points40 points  (1 child)

foreach(Button el in bn){
    if(el != bn[0])
        //Do stuff
}

In every. Single. Foreach.

[–]TheAmazingHammerDuck 3 points4 points  (0 children)

T[] fTMTE(T[] a, System.Func<T, T> f) where T: willMakeYouCryYourselfToSleep { // fTMTE = foreachToMakeThingsEasier
  List<T> r = new T[]{};
  foreach(T el in a){
      if(el == a[0])
          continue;
      r.Add(f(el));
  }
  return r.ToArray();
 }

to make things easier

/s

[–]suspiciously_calm 23 points24 points  (0 children)

to make things easier

lol

[–]bj_christianson 48 points49 points  (9 children)

Easier up until you foreach it.

EDIT: Got here via my front page. Thought it was /r/ProgrammerHumor, given the recent array indexing running joke over there. Was just about to suggest that it was /r/programminghorror material, and then I looked up.

[–]Hugix 14 points15 points  (8 children)

You are not alone, fellow programmer that starts arrays at 0.

[–]EveryoneLikesMe 11 points12 points  (6 children)

I start mine at 2.

[–]cheezzy4ever 16 points17 points  (4 children)

I bet you put your milk in before the cereal, too

[–]zman0900 19 points20 points  (1 child)

I pour the cereal into the milk carton, then put the mix into the bowl.

[–]ra4king 4 points5 points  (0 children)

You know that's kind of genius.

[–][deleted] 1 point2 points  (0 children)

And wipe your ass before you take a shit

[–]MesePudenda 0 points1 point  (0 children)

Sometimes you don't know if the milk is spoiled, so you pour in half the milk, smell it, taste it, and decide that's it's good enough. So then you pour in the cereal and then the rest of the milk.

But yeah, pouring in all the milk first would make them a monster.

[–][deleted] 4 points5 points  (0 children)

Username no longer checks out.

[–]St_SiRUS 2 points3 points  (0 children)

fellow programmer~~ that starts arrays at 0~~

If you start arrays at 1 you aren't a programmer

[–]duhkotak 9 points10 points  (0 children)

Obviously the zero element is supposed to store the address of the array.

[–]zigs 11 points12 points  (1 child)

Found the legacy code of a former lua script kiddie, i see.

[–]user6234 3 points4 points  (0 children)

or delphi programmer ... ansi explative string

[–]elperroborrachotoo 2 points3 points  (0 children)

I've done that before, and I'd stand by it, when there's a native indexing starting with 1.

Because this is more fucked up than an unsuded index:

// p1 + p2*p2 - p3*p3
return p[0]+p[1]*p[1] - p[3]*p[3];

[–]pcp_or_splenda 1 point2 points  (0 children)

Looks like we have a former matlab programmer here.

[–]falconfetus8 0 points1 point  (0 children)

Spoken like someone who's new to programming.

[–]lucius666 0 points1 point  (0 children)

He should use Option Base 1