const?? When and why? This is ugly!

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Mar 7 07:09:34 PST 2009


Derek Parnell wrote:
> On Sat, 07 Mar 2009 07:11:45 -0500, Burton Radons wrote:
> 
>> Perl would be more powerful if its strings
>> were mutable, not less, although not by much
>> due to the interpreter.
> 
> I think we have a terminology issue.
> 
> We have character arrays (some fixed length, others variable length -
> doesn't matter). In D's world view, data can be invariant (nothing gets to
> change it), const (other routines can modify it but this routine will not),
> or mutable (anything can change it). So in D we have some character arrays
> that are invariant (eg. Literals), some are const, and some are mutable. It
> is a pity that D's term "string" is being used in discussions as if it is
> synonymous with character array - but it is not. It only refers to certain
> types of character arrays - the invariant ones. We really need some simple
> terms for const and mutable character arrays.
> 

I don't think char[] is half bad. const(char)[] is a mouthful, but most 
of the time those are function parameters, where the handy in char[] 
applies.

Andrei



More information about the Digitalmars-d mailing list