Well in that example, you can always replace "scientist" with "scholar". But if I want to say "Am I also a scholar?" after thinking of saying "I am a scientist". Sure that can be handled also without much difficulty. So perhaps you can say "whether the string is mutable or not has no serious practical consequences", but I want to amend it as "whether the string is mutable or not is a conceptual difference".

On 03/22/2014 05:21 AM, Milan Bouchet-Valat wrote:
Le samedi 22 mars 2014 à 05:08 +0800, cnbiz850 a écrit :
Well, from this perspective, it makes sense why those strings should not
be mutable.

But from other perspectives, making strings immutable contradicts with
how natural languages are used.  For instance, after I said "I am a
professor", I want to say "I am a scientist", or perhaps I change my
mind and say "I am a scholar".
But when it comes to concretely changing "I am a scientist" to "I am a
scholar", you'll do this anyway:
replace("I am a scientist", "scientist", "scholar")

I really doubt you'll find plausible use cases where you'd prefer to
mutate the string. And guess what, a construct like this couldn't work:
str = "I am a scientist"
str[8:16] = "scholar"

because the replacement string is too short. Woops...


So the question of whether the string is mutable or not has no serious
practical consequences.


Regards

Reply via email to