RFC on range design for D2
Benji Smith
dlanguage at benjismith.net
Tue Sep 9 15:12:25 PDT 2008
Andrei Alexandrescu wrote:
> Andrei Alexandrescu wrote:
>> Manfred_Nowak wrote:
>>> Benji Smith wrote:
>>>
>>>> Given the use of "getNext", I think "hasNext" is a more natural
>>>> choice
>>>
>>> clapping hands.
>>
>> Walter would love that.
>>
>> for (R r = getR(); r.hasNext; r.next) { ... }
>>
>> Look ma, no negation! Oops, I just materialized one with the
>> exclamation sign.
>
> I just discovered a problem with that. hasNext implies I'm supposed to
> call next to get the thingie. It should be hasFirst, which is less
> appealing.
>
> Andrei
I see where you're coming from, because the range shrinks itself
element-by-element as it iterates, eventually disappearing into a
zero-element range.
But for me as a consumer of the container, it's a little weird.
When I visualize iteration (beware: silly metaphor ahead), it looks like
a frog hopping from one lilly-pad to another. He might have a
well-defined start and end point, but the lilly-pads don't evaporate
after the frog hops away.
When I see "isEmpty" in the implementation of an iteration routine, it
makes me think of a producer/consumer work queue. The list is only empty
if the consumer has consumed all the work items from the queue.
I get what you're saying about the iteration-range being empty because
it shrinks itself during each step of the iteration. But to me,
iteration is an idempotent operation, so something non-empty before the
iteration should not be empty after the iteration.
--benji
More information about the Digitalmars-d-announce
mailing list