On 5/4/2011 5:46 PM, harrismh777 wrote:
John Nagle wrote:
Arguably, Python should not allow "is" or "id()" on
immutable objects. The programmer shouldn't be able to tell when
the system decides to optimize an immutable.

"is" is more of a problem than "id()"; "id()" is an explicit peek
into an implementation detail.

Yes, yes, yes... and I'll go you one more...

... Python should optimize on *all* immutables when possible.


For instance:

a = (1,2,3)
b = (1,2,3)

a == b True

a is b False

To be consistent, in this case and others, a and b should reference
the same immutable tuple.

    Actually, that's not necessarily an "optimization".  The cost of
looking up small tuples is probably higher than creating them.
There's also a potential optimization of duplicating tuples in
use by different threads, to reduce locking effort.  (CPython's
global lock is too dumb to exploit this, but there are other ways
to do it.)


Or, as stated earlier, Python should not allow 'is' on immutable objects.

   A reasonable compromise would be that "is" is treated as "==" on
immutable objects.

                                        John Nagle
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to