more naming

Daniel Gibson metalcaedes at gmail.com
Sat Jan 22 09:51:39 PST 2011


Am 22.01.2011 18:46, schrieb Andrei Alexandrescu:
> On 1/22/11 11:38 AM, Torarin wrote:
>> 2011/1/22 Andrei Alexandrescu<SeeWebsiteForEmail at erdani.org>:
>>> OK, so we have replace(haystack, needle, nail) which replaces _all_
>>> occurrences of needle in haystack with nail. How would you call a
>>> function
>>> that replaces only the _first_ occurrence of needle with nail?
>>>
>>> Must be a distinct function, not a runtime parameter to the existing
>>> function. This is because the function that replaces only one occurrence
>>> only requires nail to be an input range.
>>>
>>>
>>> Andrei
>>>
>>
>> It sounds like the current replace should be named replaceAll.
>>
>> Torarin
>
> That's what I'm fearing - changing current replace to replaceAll and
> adding replace with the meaning of replaceFirst would silently change
> the semantics of existing code.
>
> Andrei

IMHO replace (without eny suffix) sounds like it replaces every occurence.
So just add replaceFirst for a function that replaces only the first 
occurence :)

Cheers,
- Daniel


More information about the Digitalmars-d mailing list