r/ProgrammerHumor • • Jun 06 '20

It's the law!

Post image
38k Upvotes

1.1k comments sorted by

View all comments

2

u/SpinatMixxer Jun 06 '20

When I started programming I knew about the i but not the j. When I encountered my first loop in a loop, I was thinking about how to name the new variable.

I did go for i, ii, iii, iiii and so on. Until my collegue saw it and explained me why that was not the way how we gonna do it.

2

u/[deleted] Jun 06 '20

sigh, that's stupid. It's obviously better to do it like i, ii, iii, iv

1

u/mypetocean Jun 06 '20

The one gotcha it has is if you forget to add the third i to iii, then you won't get a reference error due to mistyping your variable. You will unexpectedly get the value of the previous iterator!

In a similar vein to i and ii is i1 and i2, which is ugly as hell but gives you all the benefits of the "Roman numeral" approach without the difficult-to-debug gotcha just waiting to happen.