Why does `filterBidirectional` exist, and why isn't it called `filter`?
Steven Schveighoffer
schveiguy at gmail.com
Thu Mar 9 13:16:07 UTC 2023
On 3/9/23 3:06 AM, FeepingCreature wrote:
> Yes I know the stated reason, to save time initializing the range in
> `filter`.
>
> You know what I did because we didn't know `filterBidirectional` existed?
>
> I literally *walked the entire range* returned by `filter` to find the
> last matching element.
Why not `rng.retro.filter`?
> `filter` should expose `back`. By all means, let `back` lazily
> initialize, but I don't understand how `filterBidirectional` was ever
> considered acceptable. Since when do we sacrifice ease of use for
> performance? I mean, since 2011 apparently. - This is bad ergonomics,
> bad discoverability and bad API design. `filterBidirectional` delenda est.
This has been a constant debate -- should ranges be allowed to lazily
initialize on the first call to front (or back)?
I'd say no. back/front shouldn't be modifying operations. I dislike the
idea of storing a "was initialized" flag and having to check that on
every call.
That being said, there's no formal requirement for it. It's just a
convention I think Phobos should stick to for its included ranges.
-Steve
More information about the Digitalmars-d
mailing list