3 ms·
Huh, so equality isn't transitive in Go. Yikes.
by yoneda 6y ago
Huh, so equality isn't transitive in Go. Yikes.
- Spivak 6y agoEh, languages end up with this all the time with type conversions. In JS: false == undefined => false false == null => false undefined == null => true
- masklinn 6y agoFirst, your comment makes no sense: a = 1 b = 2 c = 1 a == b => false b == c => false a == c => true Is that surprising? Equality is transitive, inequality is not. Second, if you have to reach for old javascript "features" (or got forbid PHP) to defend a language you're in a bad, bad place. Third, the broken equality is not something that's usually praised about javascript. In fact the first rule of javascript equality is that there is only one situation in which `==` is the correct operator: checking that something is null (because that avoids having to differentiate between null and undefined, papering over one javascript wart using another). In every other situation you want "strict" (===) equality.
- virtue3 6y agoI managed to get my team to use `lodash.isNil` because we had gotten bitten by this crap too many times. And `lodash.isEmpty` for strings/arrays/etc.
- mirekrusin 6y agoWhat is absurd about this statement from logical point of view? A != B A != C B == C ...looks like valid logical statement, ie. A = 1, B = 2, C = 2: 1 != 2 1 != 2 2 == 2
- presto8 6y agoWhat about A=1, B=2, C=3? A != B 1 != 2 A != C 1 != 3 B == C 2 == 3
- mirekrusin 5y agoIf you write `y = x + 1` and say what about `y = 42` and `x = 0`, `42 = 0 + 1` doesn't mean math/equation is absurd, does it?
- dragonwriter 6y agoThat's not an example of nontransitivity. You’ve only shown that some nontruthy values are unequal by == and some are equal by ==. Nontransitivity would be a == b, b == c, c != a. But you have the much more expected b != a, b != c, c == a. JS loose equality is intransitive, though; the standard example being: '0' == 0; // true 0 == ''; // true '0' == ''; // false
- adonovan 6y agoIn many languages, equality is often intransitive when you consider implicit conversions. For example: type T int const a = 0 var b T = a var c interface{} = b fmt.Println(a == b, b == c, c == a) // true true false https://play.golang.org/p/YZ-0Ym5lJ7R https://play.golang.org/p/YZ-0Ym5lJ7R