bearophile wrote:
Andrei Alexandrescu:

Generally I'd be hesitant to make it all too easy to do linear
searches. Too much of that would encourage people to stick with
linear searches because it's the path of least resistance.<

D programmers know the difference between linear search, hash search
and search in an ordered search tree. They are O(n), O(1), and O(ln
n). Do you want to use a different name for each of those searches
(and maybe a (n log log n if you search with interpolated search,
etc) just because their computational complexity is different, or do
you want just a syntax that asks the collection to find something
using the faster code it has?

I think you're giving D programmers too much credit. I think a best-effort search is not widely useful.

Searching a value in a literal should actually be allowed: x in
[10, 20, 30, 0]<

This is very wrong. No special cases, please. If you don't want to
support the linear search on all arrays, then please don't add this
feature at all, I will keep using my isIn templated function (that
digests AAs too, lazy iterables, etc too of course). I don't want
more warts and special cases in D, thank you. As Python Zen says:
"Special cases aren't special enough to break the rules." Such rules
must be read and understood by D devs too, if you want to make a
language that's not a mess as C++.

Searching an array literal vs. an array variable is not a special case.

Andrei

Reply via email to