== Operator and operands

In most languages it’s the same thing. People often do 1 == evaluated value because 1 is not an lvalue. Meaning that you can’t accidentally do an assignment. Example: if(x = 6)//bug, but no compiling error { } Instead you could force a compiling error instead of a bug: if(6 = x)//compiling error { } … Read more

What’s the difference between identical(x, y) and isTRUE(all.equal(x, y))?

all.equal tests for near equality, while identical is more exact (e.g. it has no tolerance for differences, and it compares storage type). From ?identical: The function ‘all.equal’ is also sometimes used to test equality this way, but was intended for something different: it allows for small differences in numeric results. And one reason you would … Read more

Why does (“foo” === new String(“foo”)) evaluate to false in JavaScript?

“foo” is a string primitive. (this concept does not exist in C# or Java) new String(“foo”) is boxed string object. The === operator behaves differently on primitives and objects. When comparing primitives (of the same type), === will return true if they both have the same value. When comparing objects, === will return true only … Read more

Implementing -hash / -isEqual: / -isEqualTo…: for Objective-C collections

I think trying to come up with some generally useful hash function that will generate unique hash values for collections is an exercise in futility. U62’s suggestion of combining the hashes of all the contents will not scale well, as it makes the hash function O(n). Hash functions should really be O(1) to ensure good … Read more