On Monday, August 18, 2003, at 01:21 PM, Hannu Kankaanpää wrote:

> [snip]

> Strings, numbers and tuples are immutable in Python so that they
> can be used as dictionary keys. I admit that one could do away
> with this restriction by just choosing not to alter strings that
> are used as dictionary keys. But allowing this to be done could
> lead to subtle bugs, and making strings immutable doesn't do much
> harm, so why not make them immutable? It's actually just a design
> choice that weighted, which would lead to shorter dev times in
> general: immutable or mutable strings. Guido thought it was the former.

I'll refer to Objective C/Cocoa in this context again. In addition to 
providing immutable and mutable string classes, Objective C/Cocoa 
provides two dictionary classes, an immutable dictionary class and a 
mutable dictionary class.

The idea that strings should have only one value with respect to 
mutability strikes me as odd. Odder still is the rationale that this is 
for the purpose of having objects to use as dictionary keys. Can't key 
mutability be handled at the dictionary level rather than at the level 
of the constituents of the dictionary?

And while I'm on the subject, any object can be a key (or value) in a 
Ruby hash (one isn't limited to to tuples, strings and numbers for 
keys).

And furthermore, if you want to programmatically avoid accidentally 
overwriting keys, there are many other ways to do it without even 
addressing mutability questions or checking for key existence before 
insertion -- for example, draw keys from a Set object, which guarantees 
that each key taken from the set will be unique.

Finally, one can easily create, in Ruby alone, an environment with the 
same model as mandated in Python, or an environment with the same model 
used in Objective C/Cocoa, or any other environment.

There's a reason I prefer Ruby to all other programming languages for 
most tasks. It's good to see the difference from other, otherwise quite 
appealing languages, like Python.

Regards,

Mark