std.stringbuffer

Steven Schveighoffer schveiguy at yahoo.com
Thu May 1 07:55:27 PDT 2008


"Frits van Bommel" wrote
> Bruno Medeiros wrote:
>> Janice Caron wrote:
>>> 2008/4/30 Bruno Medeiros:
>>>>  Also, is there a reason why these mutable functions shouldn't be in
>>>> std.string, together with their invariant/const brethren?
>>>
>>> That's why we're having this discussion.
>>>
>>> The idea is that std.string can be optimised for invariant strings,
>>> while std.stringbuffer could be optimised for mutable strings. There
>>> are pros and cons for separate modules. I don't think Walter wants
>>> std.string "polluted" by all these functions he doesn't much care for.
>>> Also, it would be bad if mutable versions were called "by mistake"
>>> with consequent unexpected behavior.
>>>
>>
>> "mutable versions were called "by mistake" "? I don't think that point 
>> applies to D, after all, the purpose of the immutability system is for 
>> the compiler to check that this won't happen, so unless there is some 
>> compiler bug, that shouldn't happen in D.
>
> What if you wanted a modified copy of the input, but that input happened 
> to be mutable?
>
> The modifying versions should have some distinguishing characteristic to 
> separate them from the COW versions. I'd say either a different function 
> name or an extra out-buffer parameter (as long as they still work if the 
> buffer is the same array as the normal input).

Any modifying versions would take mutable strings, COW version would require 
invariant strings.  They would be able to go in the same module, because 
there would be no ambiguity.

But if you have non-modifying versions that you want to use on mutable 
strings, those would most likely take a const pointer.  Those would have to 
be named differently than the invariant versions, because invariant 
implicitly casts to const.

Besides all this, it is good to separate them into 2 different modules 
because the linker includes all functions that are in a module, not just 
ones that are used.  So if you are of the persuasion to only use mutable or 
only use COW functions, then you probably don't want to link in the other 
versions if you can help it.

-Steve 





More information about the Digitalmars-d mailing list