[clug] Somedays you use more force than is necessary...
Carlo Hamalainen
carlo at carlo-hamalainen.net
Tue Apr 29 10:38:42 MDT 2014
On 29/04/14 07:58, Hugh Fisher wrote:
> The first hit from typing 'immutable python object' into Google was a
> StackOverflow thread about how to create just such a thing. Didn't
> even require a C implementation, just a bit of metaprogramming with
> the object internals.
>
> <http://stackoverflow.com/questions/4828080/how-to-make-an-immutable-object-in-python>
>
It seems that read-only fields are not enough:
http://queue.acm.org/detail.cfm?ref=rss&id=2611829
The Curse of the Excluded Middle
by Erik Meijer | April 26, 2014
Bad as this is, surely it is enough just to abolish state mutation
to make the code pure. No! Unfortunately, it is not enough simply to
make all fields in a class readonly and disallow assignments to
local variables in order to tame the state monster. The C? program
here shows that threads can easily simulate state, even though there
are no assignments or mutable variables anywhere to be seen in the code.
....
These examples are just the tip of the iceberg. The fundamental
problem with side effects is that there are many uncontrollable ways
to observe them, and even worse, it is often possible to simulate
one effect with another. Adding recursion to pure combinatorial
circuits makes it possible to build flip-flops that provide mutable
state. You can prove that state and delimited continuations suffice
to simulate any effect,2 and that unchecked exceptions can simulate
continuations.4 You cannot be careful enough in dealing with effects.
Enjoy :)
--
Carlo Hamalainen
http://carlo-hamalainen.net
More information about the linux
mailing list