5 ms·
Just because something is a well known-flaw doesn't make it a glaring flaw. There's a reason newer JVM languages like Kotlin use == as an alias for equals inst
by dtech 5y ago
Just because something is a well known-flaw doesn't make it a glaring flaw.
There's a reason newer JVM languages like Kotlin use == as an alias for equals instead of reference equality.
- marginalia_nu 5y agoWhat if you are interested in reference equality?
- __float 5y agoIn practice, how often are you interested in it? C# has `Object.referenceEquals()` because you _may_ want this sometimes. But to have reference equality be the default for something like `==` is a design flaw. Not one that can be fixed now, of course, but it will continue to cause bugs for years to come. Sometimes, it happens in core Java libraries themselves: https://bugs.openjdk.java.net/browse/JDK-8274779 https://bugs.openjdk.java.net/browse/JDK-8274779 https://github.com/openjdk/jdk/blob/722d639fad2e4fc6eb2aabd427e2719501899cfe/src/java.base/share/classes/sun/net/www/http/HttpClient.java#L310 https://github.com/openjdk/jdk/blob/722d639fad2e4fc6eb2aabd4...
- marginalia_nu 5y agoDunno, I do a fair bit of low level java work, happens every once in a while. Curiously, I don't do a lot of value-comparisons. Based on grepping in the repo for my search engine, I appear to do one every 1000 lines of code. May just be how I write code though. Some people seem to do that a lot more.
- LordDragonfang 5y agoPython uses the `is` operator, which is semantically much more explicit (and arguably correct, though C#'s use of the `is` operator is probably more correct). edit: Kotlin uses `===`, which is another good option.
- marginalia_nu 5y ago=== seems almost more dangerous. It's a lot easier to tell == from Objects.equals(a,b) than == from ===.
- wiseowise 5y agoSeriously?
- marginalia_nu 5y agoYes. Look, languages are moving away from permitting constructs like "if (x = 1)" because it's difficult to distinguish from "if (x == 1)". Adding "if (x === 1)" into the mix is arguably a step backwards in terms of clarity.