Mutable strings

SBrunning at SBrunning at
Mon Sep 22 15:32:43 CEST 2003

> From:	Alex Martelli [SMTP:aleax at]
> Hans-Joachim Widmaier wrote:
> > I don't think strings are immutable because they ought to be that way
> > (e.g. some CS guru teaches that "mutable strings are the root of all
> > evil"). They're immutable because they allow them to be used as
> > dictionary keys. And it was found that this doesn't affect the
> > usefulness of the language too much.
> Wrong.  Consider Java, even back from the very first version: it had
> no dictionaries on which string might be keys, yet it still decided
> to make its strings immutable.  This should make it obvious that the
> interest of using keys as dict keys cannot possibly be the sole
> motivation for the decision to make strings immutable in a language.
> Rather, the deeper motivation is connected to wanting strings to be
> ATOMIC, ELEMENTARY types, just like numbers; and to lots of useful
> practical returns of that choice.  All you lose is the "ability" to
> "confuse" (type-pun) between strings and arrays of bytes in many
> situations, but that's an ability best lost in many cases.  It's not
> an issue of "evil" -- a close-to-the-hardware low-level language
> like C has excellent reasons to choose a different, close-to-HW
> semantics -- but in a higher-level language I think Python's and
> Java's choice to have strings immutable works better than (e.g.)
> Perl's and Ruby's to have them mutable.
I came across a good write up of this principle today -

Simon Brunning,

The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.

More information about the Python-list mailing list