RE: Mutable strings

Discussion in 'Python' started by SBrunning@trisystems.co.uk, Sep 22, 2003.

  1. Guest

    > From: Alex Martelli [SMTP:]
    > 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 -
    <http://c2.com/cgi/wiki?ImmutableValue>.

    Cheers,
    Simon Brunning,
    http://www.brunningonline.net/simon/blog/
    --LongSig





    -----------------------------------------------------------------------
    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.
     
    , Sep 22, 2003
    #1
    1. Advertising

  2. Wow, that's timely!
    Good write-up.
     
    Gordon Airport, Sep 22, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gordon Airport

    Mutable strings

    Gordon Airport, Sep 20, 2003, in forum: Python
    Replies:
    17
    Views:
    9,769
    Hans-Joachim Widmaier
    Sep 25, 2003
  2. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    787
    Malcolm
    Jun 24, 2006
  3. casebash
    Replies:
    9
    Views:
    448
    Jack Diederich
    Jul 27, 2009
  4. Mystifier

    Mutable strings

    Mystifier, Jan 13, 2005, in forum: Ruby
    Replies:
    19
    Views:
    347
    Eric Hodel
    Jan 14, 2005
  5. Water Cooler v2

    Are JavaScript strings mutable?

    Water Cooler v2, Apr 18, 2006, in forum: Javascript
    Replies:
    12
    Views:
    236
    John G Harris
    Apr 20, 2006
Loading...

Share This Page