for ( int i = 0; i < 10; i++ ) { printf( "%d ", i ); }Here, it's not too difficult to see what i does What if i were in the middle of a large chunk of code? Using a meaningful variable name will go a long way to enhancing the readability of code. The occasional MeaningfulComment is nice, too. And so is the avoidance of large chunks of code.
On the other hand, we're not indexing an array. It appears that we're printing the digits zero through nine: "0 1 2 3 4 5 6 7 8 9 " So would it be better to say...
for ( int digit = 0; digit < 10; ++digit ) { printf( "%d ", digit ); }
i is a meaningful variable name. It is the name of a loop index, probably because you are iterating over an array. When it is used that way, I never have any problems with it.
If you have a large chunk of code then you have other problems. You need a ComposedMethod. Loop bodies should never be more than a few lines long, and so a loop index should never be part of a large chunk of code.
There are a few single letter variable names with well understood meanings across a wide variety of programming languages. These are ...
There is also the argument from "egoless programming", which says that we should eschew possessive variable names like i in favor of the more inclusive we or us. --DaveSmith
This page mirrored in WikiPagesAboutRefactoring as of July 17, 2004