Index can be useful but start looking for mapping and sorting functions. Or foreach. If you really must index, sure go use index or I if it’s conventionally understood. But reading something like for I in e where p == r.status is really taxing to make sense of
Oh yeah, I map, filter and reduce pretty much everywhere I can. But sometimes you need the index and i is so commonly understood to be that, I’d say it could even be less legible to deviate from that convention
It’s not incoherent, it just takes a tiny bit more effort to mentally parse as it’s not a stereotypical for loop. Maybe it’s just me, but let me try and explain
With the i example if you’re familiar enough with a language, your brain will gloss over the unimportant syntax, you go straight to the comparison and then whether it’s incrementing or decrementing.
With the other example, the first my brain did was notice it’s not following convention, which then pushes me to read the line carefully as there is probably a reason it doesn’t.
I’m not saying it’s a huge difference or anything, but following code conventions like this makes things like code reviews much easier cumulatively.
Index can be useful but start looking for mapping and sorting functions. Or foreach. If you really must index, sure go use index or I if it’s conventionally understood. But reading something like for I in e where p == r.status is really taxing to make sense of
Oh yeah, I map, filter and reduce pretty much everywhere I can. But sometimes you need the index and
i
is so commonly understood to be that, I’d say it could even be less legible to deviate from that conventionIn what world is
for (int index = 0; index < objectToIterate; index++) { // DO YO THANG }
less coherent than
for (int i; i < objectToIterate; i++) { // DO YO THANG }
The world where the convention is
i
What’s incoherent about the first one? Why is index bad beyond standards
It’s not incoherent, it just takes a tiny bit more effort to mentally parse as it’s not a stereotypical for loop. Maybe it’s just me, but let me try and explain
With the
i
example if you’re familiar enough with a language, your brain will gloss over the unimportant syntax, you go straight to the comparison and then whether it’s incrementing or decrementing.With the other example, the first my brain did was notice it’s not following convention, which then pushes me to read the line carefully as there is probably a reason it doesn’t.
I’m not saying it’s a huge difference or anything, but following code conventions like this makes things like code reviews much easier cumulatively.