Fully transitive const is not necessary

Bruno Medeiros brunodomedeiros+spam at com.gmail
Sun Apr 27 16:23:58 PDT 2008


Sean Kelly wrote:
> Janice Caron wrote:
>> On 27/04/2008, Sean Kelly <sean at invisibleduck.org> wrote:
>>> what do they achieve that could not have been
>>> achieved via plain old const strings?
>>
>> In a word: (OK - in three words): Copy On Write.
>>
>> For example, one could write a function
>>
>>     string escape(string s);
>>
>> which escaped certain characters (by preceding them with '\' or
>> whatever). Because s is an array of invariant chars, if nothing needs
>> to be escaped, the function is able to return s.
> 
> So this is predicated on the idea that the optimal strategy is to assume 
> that library functions will not actually need to make any changes the 
> majority of the time, and that they do COW internally.  Fair enough.  I 
> agree that this makes it a clear win for Phobos, which is designed 
> around this assumption.
> 
> 
> Sean

And like Walter mentioned before, most modern high-level languages have 
invariant strings instead of mutable strings. Java and C# have it, and, 
if I'm not mistaken, Python and Ruby as well.


-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list