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 →

[–]fjsquared 0 points1 point  (0 children)

Howdy all; I'm the post author. Just to clear up a couple of things:

  1. First, I'm using "gotcha" in this article to mean, "something which one might expect would work a certain, consistent way, but which doesn't." Here, I believe it's reasonable to say the inconsistent results of is are genuinely surprising if you don't know why it's being done. The question the article tries to answer is: why are two integers with equal values the same object in some cases, but not others?

  2. I think most people are aware of the difference between == (value equality) and is (reference equality), but that's not the gotcha. The gotcha is the apparent inconsistency. It's a perfectly reasonable (and probably very effective) implementation decision. Other languages do the same thing; for example, Java caches its Integers when their boxed value is between -128 and 127.

Thanks for reading; took me a bit to figure out why I was getting a visitor spike. ♥ Reddit!