this post was submitted on 09 Jul 2023
629 points (94.0% liked)

Programmer Humor

32371 readers
360 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
(page 2) 38 comments
sorted by: hot top controversial new old
[–] basuramannen@discuss.tchncs.de 3 points 1 year ago (1 children)

I don't like i and j since they are commonly used for imaginary numbers. I like to start on n. Probably because I do DSP.

load more comments (1 replies)
[–] Gotoro@lemmy.world 3 points 1 year ago

I always use x or y, coming from Python background

[–] menturi@lemmy.ml 2 points 1 year ago

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.

[–] Heavybell@lemmy.world 2 points 1 year ago

I dunno why, but I have always used x, y, z for my generic for-loop variables.

[–] librecat@lemmy.basedcount.com 1 points 1 year ago

don't mind i but personally always use index or x, y, z for games

[–] Lewistrick@feddit.nl 1 points 1 year ago

chuckles in Python

[–] psysop@lemmy.world 1 points 1 year ago (3 children)

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.

load more comments (3 replies)
[–] joneskind@lemmy.world 1 points 1 year ago

I thought it come from mathematical sequences, but actually it doesn't. My best bet is that i is the shorthand for index

[–] Zucca@sopuli.xyz 1 points 1 year ago

Well. I guess I'm then a some kind of heretic then. 🤷

[–] roi@lemmy.blahaj.zone 1 points 1 year ago

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”

[–] bilb@lem.monster -2 points 1 year ago* (last edited 1 year ago) (3 children)

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.

[–] spauldo@lemmy.ml 1 points 1 year ago

foreach is useful when you don't need to know the index of something. If you do, conventional i, j, k, etc. are useful.

A lot of it depends what you're doing (number crunching, for instance) or if you're in a limited programming language (why won't BASIC die already?) where parallel arrays are still a thing.

load more comments (2 replies)
load more comments
view more: ‹ prev next ›