I always use x or y, coming from Python background
Programmer Humor
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
I started using the first letter of the thing I am iterating over. This is particularly helpful with nested loops so I can easily remember which index variable corresponds to which thing.
I thought it come from mathematical sequences, but actually it doesn't. My best bet is that i
is the shorthand for index
Well. I guess I'm then a some kind of heretic then. 🤷
When my brain doesn’t work I’ll resort to naming them the single of the plural. Like keys turns into key when i don’t wanna call it “objkey” or “outrageouslylongnamethatmayormaynotbeafittongwordtodescribeakey”
chuckles in Python
I'm honestly prefer short but (usually) complete words. Somewhere along the line I realized that being explicit really helps when you need to change it later.
don't mind i
but personally always use index
or x, y, z
for games
WTF, I have never used nor seen "j."
I don't usually have to name these variables these days though. Pretty much everything I use has foreach or some functional programming type stuff.
And like that, the off-by-one mistakes disappear.
It was very common in text books when showing nested loops
int nWhatTheCount = 0;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < i; j++) {
for (int k = 0; k < j; k++) {
for (int l = 0; l < k; l++) { // and on, and on
nWhatTheCount++;
}
}
}
}