Never, ever again will I use the letter i as a counter in a loop
Ok, so I recently read an article, maybe by Joel Spolsky, about not using i, j and k as counters. Those familiar constructs of
For i = 1 to Ubound(SomeArray())
….
next i
should be using a full variable name of some sort.
The code I’m working on right now in the Auto FE Updater has a number of loops within loops. As the outer loop got longer and longer I decided to change the use of the letter i to something more meaningful. In this case DatabaseCounter. No problem, just change the Dim statement, change the compile errors complaining about the letter i and done. No problem.
(Several hours later)
Something isn’t working right as I’m doing my final testing. I threw in debug statements here, there and just about everywhere. I examined the code with the proverbial fine tooth. Change the data I’m testing and now it’s working even stranger.
I spend at least an hour examining about 120 lines of code and suddenly see the problem.
I was using a 1 (digit 1) and not an i (letter i) in an array() reference. Yeah, yeah, looks obvious in this font. But not quite so obvious in Courier. Of course that 1 had been wrong all along. But in the limited testing I was doing before it wasn’t so obvious that there was a problem.
Now I may, very likely will continue, to use the letters j and k in very short 3 or 8 line loops. But never again will I use the letter i.