String implementations

Robert Fraser fraserofthenight at gmail.com
Tue Jan 15 19:19:46 PST 2008


bearophile wrote:
> Defining how an ASCII string is best managed by a language is already complex (ropes or not? Mutable or not? With shared parts or not? Etc), but today ASCII isn't enough and when you add Unicode matters then string management becomes an hairy topic, this may be interesting for D developers:
> 
> http://weblogs.mozillazine.org/roc/archives/2008/01/string_theory.html
> 
> Something curious: sometimes I need mutable strings, but I cope with the immutable ones when necessary. This author says that even stringAt isn't much useful! :-)
> 
> Bye,
> bearophile

I agree with pretty much everything in that article, especially the part 
about charAt not being very useful (occasionally I iterate, but rarely 
do I need random access, though slicing is a good option for strings I 
know the format of that don't need regexes).

D's "string" (that is, invariant(char)[] ) is a good compromise, 
although I'd prefer to also have a String class that I can use for 
*some* strings that can be implicitly used as (but not converted to) a 
char[] but has interning & hash code caching. But this is impossible 
within D's type system as it stands today.



More information about the Digitalmars-d mailing list