RFC on range design for D2
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Sep 10 10:53:14 PDT 2008
Bill Baxter wrote:
> Part of my argument here is that it's more natural and requires less
> cognitive load to think of things in terms of moving a cursor back and
> forth. So you won't convince me by constructing clever range unions
> and differences to achieve the same thing as a simple ++ and -- can
> do. :-)
I agree, and I agreed in the draft on ranges, that code using ranges can
on occasion be more awkward than code using iterators. I think their
advantages do outweigh this disadvantage.
>> This is fundamental. Ranges NEVER grow. They ALWAYS shrink. Why? Simple:
>> because a range has no idea what's outside of itself. It starts life with
>> information of its limits from the container, and knows nothing about what's
>> outside those limits. Consequently it ALWAYS WITHOUT EXCEPTION shrinks.
>
> Doesn't seem to be quite so absolute from my perusal of std::algorithm.
Code using iterators will naturally avail itself of all of their
advantages. Code using ranges will do the same. From my experience with
rewriting std.algorithm, the working style is a bit different. On
occasion iterators are indeed more flexible. But overall my code has
reduced in size and became safer because ranges are a higher-level
abstraction. Also often code using ranges is easier to follow because
there are fewer variables with more apparent meaning, and the progress
of the algorithm is easier to follow by tracking range shrinking.
Andrei
More information about the Digitalmars-d-announce
mailing list