4 ms·
Even "i" can be changed to "index". My rule of thumb is this: If you wouldn't use the abbreviation when speaking, don't use it when coding. I don't understan
by tmuir 10y ago
Even "i" can be changed to "index". My rule of thumb is this: If you wouldn't use the abbreviation when speaking, don't use it when coding.
I don't understand why 'i' has been given a pass. The argument boils down to saved keystrokes. Typing is not the bottleneck.
- dsfuoi 10y agoI agree, and I have calculated this a while ago this based on average number of lines a programmer writes in 8 hours. I don't have the actual numbers but unless you type slower than ~30 words per minute, speed it isn't a bottleneck. I have been using index instead of i in while loops lately. It's surprisingly concise.
- kleiba 10y agoMy guess would be that it derives from the mathematical notation for sums. But apart from that, I think using i,j,k as index variables in for-loop has become such a de-facto standard that I would only prefer long names such as "count" or "index" in situations where multiple indices may cause confusion. But then I'd probably use even more specific names than "count" or "index".
- Gibbon1 10y ago> I don't understand why 'i' has been given a pass. The reason is that in FORTRAN variables starting with i, j, k..n were defined as integers. Back in the day I learned fortran first, then basic. People that learned basic first often would use the letter 'a' as a loop index instead of 'i' Now days I still use 'i' but often use indx instead because my editor doesn't highlight single letter variables easily.
- majewsky 10y agoI'm okay with "i" (like others said, it's a well-known shorthand for "iterator" or "index") but I often use "idx" because it can easily be combined with other words in nested loops (e.g. "rowIdx" and "columnIdx").
- dllthomas 10y ago> I don't understand why 'i' has been given a pass. Because it is well enough established (in both programming and mathematics) that it communicates literally no less information to the reader than "iterator" or "index" would in the same context. > The argument boils down to saved keystrokes. Not at all. I, for one, find it easier to see the shape of the whole expression when the variable names are shorter.
- kps 10y agoYes; prolixity yields clarity in programming about as much as in prose. The old quip needs an update: a modern programmer can write COBOL in any language.
- husted 10y agoWhen I started to program in C I used "n" for the longest time, simple because it was quicker on to type on my first computer; "Next N" was a quick two taps on the N key. Guess the platform :-)
- teddyh 10y agoA ZX80, ZX81 or ZX Spectrum.