The future of Python immutability
x31eq at cnntp.org
Mon Sep 7 11:58:06 CEST 2009
John Nagle wrote:
> In the beginning, strings, tuples, and numbers were immutable, and
> everything else was mutable. That was simple enough. But over time,
> Python has acquired more immutable types - immutable sets and immutable
> byte arrays. Each of these is a special case.
> Immutability is interesting for threaded programs, because
> immutable objects can be shared without risk. Consider a programming
> model where objects shared between threads must be either immutable or
> "synchronized" in the sense that Java uses the term. Such programs
> are free of most race conditions, without much programmer effort to
> make them so.
Of course, tuples would still be a special case because they
may contain mutable objects. You need to check they're
immutable all the way down.
Nothing to do with threading, but it's also the cause of
>>a = (, 2)
>>a += 
succeeds, but raises an error.
More information about the Python-list