COW vs. in-place.

Kirk McDonald kirklin.mcdonald at gmail.com
Thu Aug 3 15:28:36 PDT 2006


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.

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://dsource.org/projects/pyd/wiki



More information about the Digitalmars-d mailing list