Generic const - a non-functional view

Dee Girl deegirl at noreply.com
Thu Jun 26 14:00:42 PDT 2008


Steven Schveighoffer Wrote:

> 
> "Dee Girl" wrote
> > Steven Schveighoffer Wrote:
> >
> >> I am not super-knowledgable about perl, but I understand the workings of
> >> invariant strings and what they mean for memory usage.  The memory usage
> >> exhibited by perl when copying one string to another suggests an entire 
> >> copy
> >> of the data, not just copying a reference.  If strings were immutable 
> >> (like
> >> they are in D or Java), then memory usage should not go up by 100MB when
> >> simply assinging two variables to point to the same data.  It actually
> >> appears to me that perl has mutable strings but only allows one reference 
> >> to
> >> the data at a time.  i.e. they are more like C++ std::strings (when not 
> >> used
> >> with references).
> >>
> >> Perhaps you can explain how my example shows they are immutable?  Maybe I 
> >> am
> >> not getting something.
> >
> > Perl has mix of reference counting with duplication and many optimization 
> > depending on code. It is mis guided to judge only by memory use. That is 
> > not relevant, just implementation detail. Tomorrow Perl is better, 
> > yesterday is bad. It is not relevant.
> >
> > What is needed to look is semantics. Strings in Perl never alias, have 
> > strict value semantics. It is same as saying they have immutable 
> > characters because you can not distinguish.
> 
> OK, I get what you are saying.  Immutability is not the important 
> characteristic, it's value-semantics.  That still invalidates Walter's 
> argument that immutability is essential to how perl strings 'just work'.

Walter had good argument with wrong words. Perl strings are good because they act like values. So are D strings. The argument is valid. 

I work more with D strings now and I never found better idea for string implementation in all language I know. It is amazing how things stay together in type system so thin.

> > 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!
> 
> I might care about whether perl decides to consume half my memory or not :) 
> But technically I don't care since I don't use perl ;)

Me not too since I use D ^_^. In general scripting language has less control of allocation. But D regex veeeery sloooow... I wish some body optimizes std.regex. Also the API of regex is very (do not know the word...) scrambled or disordered or inconsistent. When ever I use regex I must look the manual page. API is terrible and you never know what function you must call and they are not orthogonal and the names are weird. Andrei please fix ^_^. Thank you, Dee Girl




More information about the Digitalmars-d mailing list