COW vs. in-place.
Kirk McDonald
kirklin.mcdonald at gmail.com
Thu Aug 3 16:33:28 PDT 2006
Oskar Linde wrote:
> 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
Those make me think the function is /asking/ if the array/string is
capitalized, sorted, &c. For sheer, bloodyminded consistency's sake, we
could use ascapitalized, assorted, &c, but those read pretty poorly.
Hrm. On second thought, your idea is better. :-)
--
Kirk McDonald
Pyd: Wrapping Python with D
http://dsource.org/projects/pyd/wiki
More information about the Digitalmars-d
mailing list