Ranges, constantly frustrating

Regan Heath regan at netmail.co.nz
Fri Feb 14 04:10:51 PST 2014


On Fri, 14 Feb 2014 02:48:51 -0000, Jesse Phillips  
<Jesse.K.Phillips+D at gmail.com> wrote:

> On Thursday, 13 February 2014 at 14:30:41 UTC, Regan Heath wrote:
>>> Don't get me wrong, counting the elements as you iterate over them is  
>>> useful, but it isn't the index into the range you're likely after.
>>
>> Nope, not what I am after.  If I was, I'd iterate over the original  
>> range instead or keep a line count manually.
>
> Maybe a better way to phrase this is, while counting may be what you're  
> implementation needs, it is not immediately obvious what 'i' should be.  
> Someone who desires an index into the original array will expect 'i' to  
> be that; even though it can be explained that .take() is not the same  
> range as the original.
>
> Thus it is better to be explicit with the .enumerate function.

FWIW I disagree.  I think it's immediately and intuitively obvious what  
'i' should be when you're foreaching over X items taken from another  
range, even if you do not know take returns another range.  Compare it to  
calling a function on a range and foreaching on the result, you would  
intuitively and immediately expect 'i' to relate to the result, not the  
input.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d-learn mailing list