[Python-3000] Immutable bytes type and dbm modules
Guido van Rossum
guido at python.org
Wed Aug 8 04:01:35 CEST 2007
On 8/7/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> My instinct with regard to sets is the other way around,
> i.e. use immutable sets unless there's a reason they
> need to be mutable. The reason is safety -- accidentally
> trying to mutate an immutable object fails more quickly
> and obviously than the converse.
But this is impractical -- a very common way to work is to build up a
set incrementally. With immutable sets this would quickly become
O(N**2). That's why set() is mutable and {...} creates a set, and the
only way to create an immutable set is to use frozenset(...).
> If Python had had both mutable and immutable strings
> from the beginning, would you be giving the same
> advice, i.e. use mutable strings unless they need to
> be immutable? If not, what makes strings different from
> sets in this regard?
That's easy. sets are mutable for the same reason lists are mutable --
lists are conceptually containers for "larger" amounts of data than
strings. I don't adhere to the "let's just make copying really fast
by using tricks like refcounting etc." school -- that was a pain in
the B* for ABC.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list