From: Dan Sugalski Date: 2003-08-19T02:50:29+09:00 Subject: Re: Question: immutable strings as design goal? On Tue, 19 Aug 2003, Mark Wilson wrote: > I'm no matz or Guido (no surprise there), but I would point out that > Apple's Cocoa has an immutable string class and a mutable string class. Many of the Cocoa core foundation classes have mutable and immutable versions of themselves, mainly for thread-safety and speed reasons. The nice thing about immutable objects is that you can treat them as atomically accessible primitives, skipping potentially costly (though necessary) synchronization stuff. It also allows for the sharing of identical constants--if the compiler can detect that two different immutable objects are otherwise identical they can be merged into a single object, though this is rarely done for anything besides strings. > Also, while I'm speaking out of ignorance and mere supposition, > wouldn't immutable strings cause difficulties in languages with more > than one writing system? No. String constants are string constants, no matter how they're encoded or how many characters are in them. The one place that immutable strings can be problematic is if you're using Unicode and your string constants use a different normalization form than some of the operations in the language or library do, but that's more a speed issue than anything else, since the runtime will end up having to decompose or recompose (depending on what uses which forms) as the program executes. Dan