[OT] What is more readable?

simendsjo simen.endsjo at pandavre.com
Mon Aug 9 18:10:36 PDT 2010


On 10.08.2010 02:53, simendsjo wrote:
> 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 :)

And on the other hand; I doubt anything of what I write will ever get 
into phobos!
Of course.. Nothing should without careful reviewing :), but after I've 
just looked at a small part of the source, I hear it screams at me!

What I've seen so far (very, very little) is actually very good, short, 
concise, readable code. I'm pretty sure I'll learn a lot from the phobos 
source!
But as any codebases it shows age. There are many different coding 
styles, commented out code, i/j/k/etc.
I'm just trying to put focus on the little things as I walk through the 
source.


More information about the Digitalmars-d-learn mailing list