5 ms·
Why is value-equality inherently more sane than identity-equality, in an object-orientated language? Value-equality takes an unbound amount of time to compute,
by chrisseaton 9y ago
Why is value-equality inherently more sane than identity-equality, in an object-orientated language? Value-equality takes an unbound amount of time to compute, as well.
- zeptomu 9y agoI agree, that's why I revised my answer (see edit). Probably comparison by-value is more useful in higher-level and comparison by reference in lower-level languages.
- deathanatos 9y agoComparison by value tends to be more useful, and more often what a user expects "==" to mean. In some ways, "==" mirrors the mathematical =. (Not exactly, of course, since mathematics is usually making statements of fact: x = 2 means x is equal to 2, not x is assigned the value 2.) I think Python is a good example here, where referential comparison is the `is` operator: `a is b`.
- hyperpape 9y agoWhat's the meaning of new Long(5) == new Long(5);? I know why the implementation lets me ask that question and I know why it's false, but I'd say that there's no reasonable question I'd ever want to ask using that expression.
- chrisseaton 9y agoYou can think up an unreasonable example for anything though. If I have a graph data structure then `node == node` with identity does make sense to me in lots of cases. And what's the value equality of `(new Object()).equals(new Object())` - they have no value.
- hyperpape 9y agoThe point is that the language treats numbers as objects when they aren't. It's not that reference semantics don't have a place, it's just that the place isn't numbers. As for your second question, it looks like the type system has two embarrassing questions: what the heck does "new Object()" mean? Nothing worth saying.
- chrisseaton 9y agoI use `new Object()` in my code and I use it exactly for identity equality! If I want a unique ID for something I create a new object and it's guaranteed it will never be reference equality to any other object anyone else could construct.