[OT] What is more readable?

Jonathan M Davis jmdavisprog at gmail.com
Mon Aug 9 17:40:51 PDT 2010


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


More information about the Digitalmars-d-learn mailing list