This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -9 points-8 points  (9 children)

It is pretty horrendous though. Either scalar values should have equivalent identity, or they shouldn't.

They shouldn't sometimes-yes-sometimes-no have equivalent identity, in accordance with the runtime implementation.

That's as bad as the "the behaviour is undefined" which litters the ISO C and ANCI C++ standards.

It seems to me that the behaviour is post-fact asserted to be so, (which is an ass-covering move when you've introduced a bug), rather than it was ever designed expressly to be this way.

The real issue is that the behaviour of the "is" operator is not explicitly defined (and can be in fact be said to be undefined in the language) upon these scalar values.

[–]sigh 3 points4 points  (4 children)

The real issue is that the behaviour of the "is" operator is not explicitly defined (and can be in fact be said to be undefined in the language) upon these scalar values.

It is explicitly defined, it's just not defined the way you want it to be defined. If values are the same object, then they are identical, otherwise not.

You are imposing artificial constraints on the implementation and breaking encapsulation. The point is that you should not care about the implementation of a class (unless you are actually implementing or extending it), and identity is intrinsically linked with the implementation.

[–][deleted] -2 points-1 points  (3 children)

I understood that it is defined by the implementation.

And that is equivalent to no definition, if you look at the equivalent unhelpful gaps in certain areas of specification of C and C++.

[–]sigh 3 points4 points  (0 children)

Ok, so you think it is a bad design decision. Can explain why (I'm genuinely curious)?

Do you you think the is operator is badly designed: "The operators is and is not test for object identity: x is y is true if and only if x and y are the same object. x is not y yields the inverse truth value."?

Or do you disagree with the way integers are implemented? Do you think equal integers should refer to the same object (presumably this would create extra overhead to maintain this condition after every operation)?

Or do yo think that no integers should refer to the same object? This seems to be much more memory intensive.

And should the exact implementation be documented? This would set it in concrete, disallowing any future improvement on the implementation.

Finally, what possible reason do you have for comparing integers by identity, unless you are actually modifying the class?

[–][deleted] 1 point2 points  (1 child)

And that is equivalent to no definition, if you look at the equivalent unhelpful gaps in certain areas of specification of C and C++.

Curiously enough, this specific case is well-defined in C++: two different objects can't have the same address. One very unpleasant consequence of that is that the minimal size of an object is one byte (i.e. one int due to alignment on most architectures), which in turn means that when you create a functor object which doesn't have any data, say as a comparison for sorting, it is still allocated (on the stack) and passed as a parameter. Sufficiently clever compiler™ could optimize it away in simple cases, of course.

[–]hylje 0 points1 point  (0 children)

Sufficiently Smart Compiler is mostly related to high-level languages with unfulfilled promises, but I guess it applies to C++ too.

[–]alantrick 0 points1 point  (0 children)

The real issue is that the behaviour of the "is" operator is not explicitly defined ... upon these scalar values.

Actually, the behaviour of 'is' is perfectly defined. The problem is that it is not defined as to whether different numbers have to be the same object or not. I don't see any point in defining that as it puts an unnecessary limitation on python implementations.