On 2021-05-28 at 12:22:22 +1000, Chris Angelico email@example.com wrote:
[...] calculate something once and reuse the value, because you know that it won't change (or don't care if it changes) [...]
(Some day I'll learn how to do this in real life. Why can't I buy just one egg, and then reuse the same egg for every meal?)
Those are mutable eggs. Try immutable eggs instead.
Or obtain a hen, aka an egg factory (and a rooster, too, but that's off topic, even for Python Ideas).
>>> egg = Egg() >>> egg.scramble() >>> egg.fry() Traceback (most recent call last): File "<stdin>", line 1, in <module> EggStateError: cannot fry a scrambled egg
Mutability is the root of all evil.