COW vs. in-place.

Oskar Linde oskar.lindeREM at OVEgmail.com
Thu Aug 3 15:40:54 PDT 2006


Kirk McDonald wrote:
> renox wrote:
>> Dave wrote:
>>
>>>
>>> What if selected functions in phobos were modified to take an 
>>> optional parameter that specified COW or in-place? The default for 
>>> each would be whatever they do now.
>>>
>>> For example, toupper and tolower?
>>>
>>> How many times have we seen something like this:
>>>
>>> str = toupper(str); // or equivalent in another language.
>>
>>
>> In ruby, they have this nice convention that a.function() leaves a 
>> unchanged and a.function!() modifies a.
>>
>> Something like this would be nice, the hard part is choosing the 
>> correct naming convention so that it is followed..
>>
>> functionXIP (eXecute In Place), functionWSD (With Side Effect)?
>> Sigh, hard to achieve something as simple and elegant as '!' : caution 
>> this function modifies the object!
>>
>> In the absence of proper naming termination, an optionnal parameter 
>> could be used yes.
>>
> 
> What about:
> 
> void   toupper(char[] s);  // Modifies s in-place
> char[] asupper(char[] s);  // COW function
> 
> Of course, this convention would only apply to functions named 
> "tosomething", but I bet most/all of the functions for which an 
> "in-place" operation makes sense are named that.

It doesn't really apply to functions that are verbs, like capitalize, 
sort and map.

For those one option is: capitalized, sorted and mapped for COW versions.

/Oskar



More information about the Digitalmars-d mailing list