Making immutable instances
Giovanni Bajo
noway at sorry.com
Thu Nov 24 20:24:01 EST 2005
Paul Rubin wrote:
> "Giovanni Bajo" <noway at sorry.com> writes:
[pay attention to the quoting, I didn't write that :) ]
>>> Mike Meyer wrote:
>>>
>>> However, when you prevent a client from adding an attribute, you're
>>> not merely making your objects immutable, you're making them
>>> static.
>
> No I don't believe that. If an object is immutable, then
> obj.serialize() should return the same string every time. If you can
> add attributes then the serialization output will become different.
I guess it might be argued that the method serialize() could return whatever
value it returned before, and that the added attribute could be "optional" (eg.
think of it as a cache that can be recomputed from the immutable attributes at
any time).
It's kind of a grey area. Surely, I would *not* mind if language support for
immutability prohibited this :)
--
Giovanni Bajo
More information about the Python-list
mailing list