Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Well.. aren't loops about interating over the indices?
And yes you should. The only right way is using "cI", "theX" or "n" as index. -
C0D4681385yi = index / iterator
So why wouldn't you use it?
Depending on what your iterating over it makes perfect sense usually. -
unless it's a traversal of spatial coordinates/array that represents space, where i use axis names as control vars (x, y, z), or something more complex when there are valid descriptive names for each index, i always use
"c" for a single loop, and "c1, c2,..." for nested ones.
derived from "cyklus", which is my native language's word for loop (and kinda works in english too, since 'cycle' is a word).
OR, if it's a loop used to do interpolation over time in unity coroutines, i do t, except those are while(t < 1) loops with increment happening in body as "t += Time. deltaTime;"
"i, j, k" always seemed like a vestige crap from ye olden days where single-letter names when people thought it somehow saves on memory or something, or when most programmers were mathematicians who are forbidden from havin useful variable names in formulas.
i also don't remember when's the last time (except the loop's "c", interpolation loop's "t" , and x/y/z coords) i used ANY single-letter variable. -
I try to use "row" and "col" for loops on a matrix. Personally, I think I,j are terrible - they look too similar and they have zero context most of the time. If it's a single loop, I use idx.
-
eeee31505y@jdebs that's often available in functional languages, but often unnecessary. I use Kotlin (multi paradigm) and I usually use
@highlight
collection.forEach { println(it) }
// Instead of
collection.forEachIndexed { index, item -> /* ...*/ } -
With the thinking of "somebody else has to maintain this" using a naming convention that you like and have to explain why you like it doesn't seem like the best approach to me. Using I, j, k... Is expected as convention and results in the same functionality.
If the index makes sense to the data being iterated over then a better name can be used but its usually independent. -
@NoToJavascript you obviously don't use vim then. What would you choose if the ide forced you to choose.
-
@netikras shouldnt j and k only be used within a nested for loop? So, they should be either related to either the element in the original list that's being iterated or defined in a parent loop. It's always going to be an element of a list anyway and the name of the list should be descriptive enough to tell you what the elements are.
-
@cmarshall10450 name it whatever you want. Just make sure it's obviously clear what the name means and why the name has been chosen.
-
I use 'i' as index only when my for loop is complex...
P.S.: This was my attempt at a joke -
Root825995yI rarely use loops without named vars, but when I do, I use `i` or `a` or `c`.
`i` because tradition
`a` because the loop var is the "accumulator" (CS habit)
`c` out of assembly habit (cx) -
Loop I,v for index and value
Loop inside of the loop o,p because why not
Loop inside of that loop u,y
Related Rants
Should I be ashamed?
I hardly ever use "i" as a counter in for loops
I most likely use "k" and "j"; "i" stands for "index"
rant
i
iterators
k
loops
j
for