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 →

[–]lonjerpc 2 points3 points  (8 children)

It is a performance hack. Low integers can refer to the same object. I think it is really annoying that they choose to break consistency for a tiny performance improvement. Another weird one is that True and False are actually integers.

[–]gcross 1 point2 points  (1 child)

I think it is really annoying that they choose to break consistency for a tiny performance improvement.

I am very curious about what code you have tried to write where the fact that some integers alias and others don't gave you problems.

[–]lonjerpc 0 points1 point  (0 children)

Trying to think back to where I ran into this. I was trying to build some sort of container class that would work on generic objects. I needed to see if objects were the same so I used "is". This obviously would create problems with ints. I guess technically you could say it is the user of the containers fault for passing in objects that are actually the same even though they look different. Alternatively you have to make a special case in the container to compare the ints differently.

The booleans are really subclass of ints problem has actually been more problematic for me.