Hacker News new | ask | show | jobs
by anon4 3909 days 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!

3 comments

I 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?
Yeah, 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.
That'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.
I imagine depending on the assumptions, the same could happen in Rust, given Rust allows overriding equality too.
Most of the time in rust, you can just `#[derive(Eq)]` and be done with it, so those kinds of things are far less likely.