Should this work?

Regan Heath regan at netmail.co.nz
Mon Jan 13 04:53:07 PST 2014


On Fri, 10 Jan 2014 16:30:12 -0000, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> On 1/10/14 6:07 AM, Regan Heath wrote:
>> On Fri, 10 Jan 2014 08:16:53 -0000, Andrei Alexandrescu
>> <SeeWebsiteForEmail at erdani.org> wrote:
>>
>>> On 1/9/14 11:56 PM, Jacob Carlborg wrote:
>>>> On 2014-01-10 02:34, Manu wrote:
>>>>
>>>>> Or just alias the functions useful for string processing...
>>>>
>>>> I agree. It already has some aliases, converting to lower and  
>>>> uppercase.
>>>
>>> I wouldn't want to get to the point where many functions have 2-3  
>>> names.
>>
>> This is only a problem if they are all in the same sphere of concern..
>> by that I mean if you're looking for string functions and you find 2
>> names for the same function this would be wrong/confusing/pointless.
>> But, if you have one name in the string category and one in the range
>> category and they were both the same function underneath I don't see
>> this as the "same" problem, right?
>
> 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).

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

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.

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?

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d mailing list