Re:A Dictionary of Single-Letter Variable Names
by liampulles on Monday October 14, 2024 @03:44AM
(#41835183)
If I'm looking at a for loop, my expectation is that the loop variable will be i. I'm against single letter vars as a general rule but I think this is a fair exception
[ Parent
| on HN ]
Re:A Dictionary of Single-Letter Variable Names
by bluerooibos on Monday October 14, 2024 @07:48PM
(#41843469)
I'd prefer i to be a description/name of the thing that is being iterated.
If your array is named cars then you can safely assume i will be a car, but depending on the complexity of the code it just adds another step for me to parse, when I could have just named it car to begin with.
That's a simple case where the data being iterated over is clear. When the data is complex, it becomes even more useful to descriptively name i so that you can more easily see what you're working with.