The future of Python immutability
John Nagle
nagle at animats.com
Fri Sep 4 00:20:55 EDT 2009
Gabriel Genellina wrote:
> En Thu, 03 Sep 2009 15:03:13 -0300, John Nagle <nagle at animats.com>
> escribió:
>
>> Python's concept of immutability is useful, but it could be more
>> general.
>>
>> 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.
>
> In the current CPython implementation, every object has a reference
> count, even immutable ones. This must be a writable field - and here you
> have your race condition, even for immutable objects.
That's an implementation problem with CPython. I'm looking at this as
a language design issue. Shed Skin, which is garbage-collected, doesn't
have that problem. Look ahead to a new generation of Python implementations
that go fast and use multiprocessors effectively.
John Nagle
More information about the Python-list
mailing list