Why I (Still) Won't Use D

Walter Bright newshound1 at digitalmars.com
Fri Mar 28 03:00:33 PDT 2008


Janice Caron wrote:
> On 28/03/2008, Walter Bright <newshound1 at digitalmars.com> wrote:
>> Making strings arrays of invariant makes them implicitly copy-on-write.
> 
> We're drifting off topic here, but ... I don't think that's right.
> 
> Example:
> 
>     string s = "hello";
>     string t = std.string.replace(s,"x","y");
>     assert(s == t); // OK
>     assert(s is t); // *FAILS*
> 
> This example demonstrates that std.string.replace() does not do
> copy-on-write. (Instead, it does copy-always). Thus, as I was saying,
> whether or not copy-on-write is done is part of the algorithm, not
> part of the type.

Ok, that's true up to a point. COW implies you *must* copy it if you 
change it, but copying it anyway doesn't really break COW, it's just 
inefficient.


>>  More generally, whether D arrays are copy-on-write or not is based on
>>  whether the element type is invariant or mutable.
> 
> Again, it is /possible/ to implement copy-on-write using mutable
> strings (as MSVC++ std::string proves) - just very difficult. But D's
> immutable makes it easy.

D 1.0 also has COW with mutable types, but the problem with it was you 
had to rely heavily on the programmer to not make a mistake with it. 
This led to code that excessively dup'd strings "just to be sure."


>> It isn't based on if
>> the contents are text or not.
> 
> No argument there! :-)

Then I guess we close with still no particular reason why strings and 
vectors cannot be the same!



More information about the Digitalmars-d mailing list