COW vs. in-place.

Kirk McDonald kirklin.mcdonald at gmail.com
Mon Jul 31 21:19:25 PDT 2006


Dave wrote:
> Sorry, I think some of that got lost in the thread...
> 
> I'm asking if it would make sense to change the current functions so COW 
> is optional. That way current code wouldn't be broken but we'd have the 
> choice.
> 

Using a function parameter as you suggest is fine and all (it helps in 
code re-use as your example ably shows), but I find calling, e.g. 
islower_inplace clearer than some strange 'false' parameter at the end 
of the argument list. If we make the 'cow' parameter default to 'true', 
we might also provide a wrapper:

char[] inplace_wrap(alias fn)(char[] s) {
     return fn(s, false);
}

alias inplace_wrap!(tolower) tolower_inplace;
alias inplace_wrap!(toupper) toupper_inplace;
// &c, &c

(I like this method of function wrapping, can you tell?) Or we could 
just as easily default cow to 'false' and have the wrapper be 'cow_wrap' 
instead. (It would also be easy enough to provide both.)

> If everything was done inplace in Phobos, then it would become 2nd 
> nature for the owner to dup when needed. And the user wouldn't need to 
> rely on the hope that the library developer didn't make a mistake and 
> forget to COW when they were supposed to.

I sure hope the library makes this an important, documented part of its 
interface.

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



More information about the Digitalmars-d mailing list