Range length property
H. S. Teoh
hsteoh at quickfur.ath.cx
Tue Apr 10 23:22:44 UTC 2018
On Tue, Apr 10, 2018 at 10:07:40PM +0000, Cym13 via Digitalmars-d-learn wrote:
[...]
> On the other hand I don't think the end user should have to scratch
> his head to find the length of a range, especially if it's not trivial
> to get (say, O(log n) kind of case). Therefore exposing a method in
> any case seems the best from an API perspective.
>
> But to avoid the performance issues mentionned earlier it means it
> should bear a different name (get/setLength comes to mind). I believe
> this is the same kind of issue that lead to having "in" for
> associative arrays but not regular ones. However this also leads to
> less coherent APIs in contradiction with the principle of least
> surprise.
[...]
I've run into this in my own code, and I've been using `walkLength` as
the name of the method, just for consistency with Phobos' walkLength.
I'm not 100% sure this is a good idea, since overloading Phobos names
can sometimes lead to annoying symbol conflict situations. But the one
good thing is that you won't forget what it's called because it's so
familiar.
T
--
An elephant: A mouse built to government specifications. -- Robert Heinlein
More information about the Digitalmars-d-learn
mailing list