4 ms·
C++ is the only language I've used, where a collection of completely reasonable decisions led to the situation that "if (a == b)" worked fine, but "if (b == a)"
by anon4 11y ago
C++ is the only language I've used, where a collection of completely reasonable decisions led to the situation that "if (a == b)" worked fine, but "if (b == a)" crashed the program due to a failed assertion.
And we weren't even using any templates!
- FreeFull 11y agoI imagine depending on the assumptions, the same could happen in Rust, given Rust allows overriding equality too.
- Retra 11y agoMost of the time in rust, you can just `#[derive(Eq)]` and be done with it, so those kinds of things are far less likely.
- tarpherder 11y agoI fail to see how reasonable decisions lead to the situation where a == b works "fine" while b == a effectively crashes the program. Could you elaborate what the reasonable decisions were?
- flohofwoe 11y agoYeah, this sounds more like a and b are different types but somebody messed up overriding equality operators. I wouldn't blame the language for that.
- devit 11y agoThat's possible in any language that doesn't force you to include a computer-checkable proof that your overridden equality operator forms an equivalence relationship.