On Sunday, September 25, 2016 13:40:14 pineapple via Digitalmars-d wrote:
> On Sunday, 25 September 2016 at 11:48:38 UTC, Jonathan M Davis
>
> wrote:
> > It's because ranges are effectively a sliding window over
> > whatever they're iterating over.
>
> I think this is the difference in perception - ranges do not
> _have_ to be sliding windows, they can just as well be windows
> that don't move. I find the latter approach to be more workable
> and intuitive that the former, and in almost every case the
> approach results in more concise and performant code for
> performing those operations.
>
> When would I ever want `range[0]` to give me the same thing as
> `range.front`? I want it to give me the first item in the range's
> view at the time of its creation.

You're going to be better off if you stop trying to think like there's some
sort of original range here. What you have right now is what you have. The
first element is index 0, and whether the range was just created or whether
it's had a million elements popped off the front is irrelevant. If you want
access to elements that aren't currently in the range, then you need to save
the range and keep that around so that you can access _that_ range instead
of the one that you currently have. Remember that many ranges are generative
and aren't backed by any sort of container and that there is no original
range that's been iterated over, and index 0 couldn't have anything to refer
to except for the current front.

And if you don't like how D's ranges are designed, sorry, but it's never
been like what you're suggesting, and changing it now would break a ton of
code even if we agreed that it were a good idea, and you're not going to get
that agreement. What we have with ranges right now is by no means perfect,
but the whole design is based on the sliding window concept - just like
D's dynamic arrays are - and that has worked fantastically for us.

> I strongly oppose any change that makes the former approach an
> inherent part of D. I honestly don't think the latter approach
> should be an inherent part of D, either, but I'd have a hell of a
> time trying to use the language if it wasn't an option.

The way it works now is how it's always worked with dynamic arrays and
ranges in D. If you're trying do anything else, you're just going to run
into problems in the long run - particularly when interacting with code
written by anyone else. So, while you're obviously free to do whatever you
want with your own code, don't expect Phobos or D code in general to change
how ranges fundamentally work.

- Jonathan M Davis

Reply via email to