On 5/11/12 1:33 PM, Mehrdad wrote:
On Friday, 11 May 2012 at 18:18:21 UTC, Andrei Alexandrescu wrote:
At the same time it clarifies, documents, and statistically verifies
that you pass a sorted range. Also, D's binary search works with
non-array ranges, but C#'s works only with arrays (which it assumes
sorted only by convention).
I think we copiously made the right call there.
Andrei
Right, right, I understand all of that...
But just because the *reasons* are correct that doesn't mean it's more
intuitive.
("Intuitive", by definition, means that you have a good chance of
getting it right without needing to look it up. Binary searching in D
failed this miserably for me.)
Totally agreed. Intuition is supported by having seen the same or a
similar pattern before. In this case D takes an unusual approach, which
I think is better than the established approach.
I have added a reference
(https://github.com/andralex/phobos/commit/650609be9b4146db3526b50ccfca6776fed73b51)
such that searching the page std.algorithm for "binary search" will lead
to the correct reference.
Andrei