this post was submitted on 09 Jul 2023
336 points (100.0% liked)

Programmer Humor

854 readers
1 users here now

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

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] StudioLE@programming.dev 18 points 1 year ago (5 children)

A useful tip I picked up was to use ii instead of j for an inner loop. It's far more distinct than j.

If for some terrible reason you have even more inner loops you can easily continue the trend i, ii, iii, iiii, iiiii - or iv, v if you're feeling roman

[–] hstde@lemmy.fmhy.ml 17 points 1 year ago

If you have the need to nest 5 levels of for-loops, I suggest taking a step back and rethinking your approach, my friend.

Even if that other approach is just refactoring it into separate methods.

[–] biscuit@lemdro.id 2 points 1 year ago

I just do i2, i3, etc

[–] exu@feditown.com 1 points 1 year ago

Two or three "i"s is readable, but any more and you're counting.
I'Ve started using i, k, m, n that's usually enough.

[–] barsoap@lemm.ee 1 points 1 year ago

When you have multiple indices you're also bound to have multiple cardinals those indices count up to, say foo.length and bar.length, so foo_i and bar_i are perfectly legible and self-documenting. A bit Hungarian but Hungarian is good in small amounts. Unless you're dealing with width and height in which case it's x and y but it's not that width_i would be incomprehensible.

[–] Gork 1 points 1 year ago

At this point we might as well go full Roman as you suggested. MXMCIIV to MXMCCVII as indices.