On Wed, 22 Jan 2014 19:39:14 -0000, Andrei Alexandrescu <[email protected]> wrote:

On 1/13/14 4:53 AM, Regan Heath wrote:
On Fri, 10 Jan 2014 16:30:12 -0000, Andrei Alexandrescu
<[email protected]> wrote:
The way I see it one learns a name for an algorithm (low cognitive
load) and then uses it everywhere. This is not Go.

Sure.  But, lets take an example: std.algorithm.canFind is more or less
what you might call std.string.contains (which does not exist - instead
we'd use indexOf != -1.. I think).

Well there's no perfection in this world :o).

What is the harm in having an alias in std.string called contains which
simply calls std.algorithm.canFind?

I think you can answer that for yourself. Just take the approach to its logical conclusion.

You mean the best possible name in all contexts, yes!  :p

Seriously, I am not suggesting we do this for all functions all the time, but just enough so that most users find what they expect to find and get what they expect to get, where it doesn't break D's philosophy of not doing inefficient things for the sake of being generic of course.

Sure, it opens the door to someone using both canFind and contains on
strings in their code.  So what?  Use of contains is more
likely/intuitive for string related code, but both are intelligible.
canFind will be more likely in generic code, where you would think of
that generic algorithm name.

It seems to me that people think of algorithms by different names in
different contexts.  In the context of strings "contains" would make the
most intuitive sense to the most people.

I agree that good names are difficult to find. I think you'd have a hard time with a "the more the merrier" stance.

This. Not my position. Rather I am suggesting we identify individual omissions (like std.string.contains) and add an alias. So that people don't have to struggle quite so much when switching to D. The lower the bar and all that..

Side-issue.. from std.algorithm:

bool canFind(alias pred = "a == b", R, E)(R haystack, E needle) if
(is(typeof(find!pred(haystack, needle))));
Returns true if and only if **value** can be found in range. Performs
Ο(needle.length) evaluations of pred.

What is **value** shouldn't that be needle?

Please file a bug or pull request. Thanks!

Bug filed.

R

Reply via email to