3 ms·
They don’t have to return bool. Even when they return bool, in some cases both greater and less must return false. Example: https://en.wikipedia.org/wiki/NaN#C
by Const-me 7y ago
They don’t have to return bool.
Even when they return bool, in some cases both greater and less must return false. Example: https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN
- masklinn 7y agoI'm not saying you shouldn't be able to implement both such that they're not coherent, I'm saying requiring implementing both when the system could provide one based on the other (as e.g. Haskell, Rust or Python do) is an unforced error and a pointless footgun.
- Const-me 7y ago> unforced error and a pointless footgun I think it’s the other way. Providing one based on the other is a pointless footgun. The experience doesn’t end when you’ve made machine code from your source. Developers debug stuff. Developers support their products, sometimes analyzing crash dumps. The more magic is used in the compiler, the harder it is to debug and support software. Sometimes that’s justified, e.g. in C# there’s substantial amount of compiler magic for generators and async functions. But these 2 features save substantial amount of code complexity. Implementing != from == and > from < only provides minimal profit. The manual implementation is a single line method. Another reason, C# is different language than Rust or Python. It has awesome support for OOP and runtime reflection. What should happen if you use reflection to get op_Inequality for a class where only == is defined? What should happen if you define == in a base class and != in a derived one?