nathan.alexander.rice at gmail.com
Fri Feb 10 19:14:26 CET 2012
>> Lets also not forget that knowing an object is immutable lets you do a
>> lot of optimizations; it can be inlined, it is safe to convert to a
>> contiguous block of memory and stuff in cache, etc. If you know the
>> input to a function is guaranteed to be frozen you can just go crazy.
>> Being able to freeze(anyobject) seems like a pretty clear win.
>> Whether or not it is pythonic is debatable. I'd argue if the meaning
>> of pythonic in some context is limiting, we should consider updating
>> the term rather than being dogmatic.
Sweet, looking at the reason for rejection:
1. How dicts (and multiply nested objects) should be frozen was not
2. "frozen()" implies in place, thus confusing users
3. freezing something like a list is confusing because some list
methods would disappear or cause errors
4. Because automatic conversion in the proposal was seen as too
involved to be so magical
5. Because frozendicts are the main end user benefit, and using dicts
as keys was seen as "suspect"
Honestly, as far as #1, we already have copy and deepcopy, the can of
worms is already opened (and necessarily so). For 2, choose a better
name? For 3, we have abstract base classes now, which make a nice
distinction between mutable and immutable sequences; nominal types are
a crutch, thinking in terms of structure is much more powerful. I
agree with point 4, if magic does anything besides make the code
conform to what an informed user would expect, it should be considered
heretical. As for #5, I feel using a collection of key value
relations as a key in another collection is not inherently bad, it
just depends on the context... The mutability is the rub. Also,
immutability provides scaffolding to improve performance and
concurrency (both of which are top tier language features).
I understand that this is one of those cases where Guido has a strong
"bad feeling" about something, and I think a consequence of that is
people tread lightly. Perhaps I'm a bit of a language communist in
that regard (historically a dangerous philosophy :)
As an aside, I find it kind of schizophrenic how on one hand Python is
billed as a language for consenting adults (see duck typing, no data
hiding, etc) and on the other hand users need to be protected from
themselves. Better to serve just one flavor of kool-aid imo.
More information about the Python-list