On 10.08.2010 02:40, Jonathan M Davis wrote:
On Monday, August 09, 2010 17:20:07 simendsjo wrote:
Continuing "my what is more readable" thread (just shut me up, but I
don't always agree with i, j, k etc...):
Personally, I think that i is just fine in many cases where it's quite clear
what
you're doing. e.g. the standard for loop:
for(size_t i = 0; i< a.length; ++i)
//whatever we do with a[i]...
foreach does reduce how often that sort of thing is necessary though. However,
once you get beyond i, and maybe j, it just gets confusing (not to mention the
fact that i and j look a fair bit alike). So, personally, I avoid going beyond
i, and I don't use i unless it's quite clear what I'm doing. Other than that, I
find clearly named variables make the code much easier to read and understand -
especially if someone else wrote the code, or you haven't read it in a while.
- Jonathan M Davis
I also use "i" in my for loops. Always!
But I still find it difficult to understand when there are more than one
index in use.
The thing here is that I couldn't understand the function top to bottom..
"j" was used both by the incrementer in the for loop, in the indexOf and
the if statement. I had to get to the indexOf before I could understand
what "j" was.
Of course, I'm just pointing out very small areas of potential
improvement as I've only covered 5% of the spec and 1% of the stdlib :)