‘is’ operator behaves differently when comparing strings with spaces

Warning: this answer is about the implementation details of a specific python interpreter. comparing strings with is==bad idea. Well, at least for cpython3.4/2.7.3, the answer is “no, it is not the whitespace”. Not only the whitespace: Two string literals will share memory if they are either alphanumeric or reside on the same block (file, function, … Read more

In Ruby, why does inspect() print out some kind of object id which is different from what object_id() gives?

The default implementation of inspect calls the default implementation of to_s, which just shows the hexadecimal value of the object directly, as seen in the Object#to_s docs (click on the method description to reveal the source). Meanwhile the comments in the C source underlying the implementation of object_id shows that there are different “namespaces” for … Read more

If Java’s garbage collector moves objects, what is Object.hashCode and System.identityHashCode?

.NET’s implementation is intentionally not published (and when you attempt to decompile it, you will find that it makes an unmanaged framework call). The only documentation as such is here, which only states that it is “not guaranteed to produce a different value for each object”, and “may change between framework versions”. Making any assumptions … Read more

tech