Generic const - a non-functional view

Bill Baxter dnewsgroup at billbaxter.com
Thu Jun 26 12:14:37 PDT 2008


Dee Girl wrote:
> Steven Schveighoffer Wrote:
> 
> You assign $y = $x. Two things could happen, a refcount is done or a full copy is done. You do not know. But you do not care! You care if changing one character in $x changes one character in $y. That never is happen. Which means semantically Perl strings are as good as strings of invariant characters. They never alias mutable data. This is the important thing. 

I certainly care if a 100MB string is getting duplicated.  It's most 
definitely going to change how I write the algorithm to manipulate that 
string.

"Act like value type" and "are immutable" are two categories which have 
overlap, but they are not identical.  Walter keeps saying strings in 
perl are immutable, but Steven's test demonstrates that (at least for 
100MB strings) they are not immutable, but they do act like value types.

This difference is relevant since Walter has often argued that invariant 
strings are the way to go based on the "fact" that they have been such a 
success in languages like Perl.  And the implication is clear there (to 
me any way) that by 'invariant' he means invariant in the sense that D2 
strings are invariant.  If he wants to include Perl in his argument he 
should be saying "value type strings" rather than "invariant strings". 
Or he should just stick to using Java as his example.  :-)

--bb



More information about the Digitalmars-d mailing list