4 ms·
> the symbol it is using is overloaded with binary comparison operator, so the people will be confused I think most people would expect expressions like `5 < x
by Ukv 2y ago
> the symbol it is using is overloaded with binary comparison operator, so the people will be confused
I think most people would expect expressions like `5 < x < 10` to work as they do in math, without necessarily thinking about it in terms of being an overloaded binary operator. The result in other languages that `5 < 12 < 10` = `true < 10` = `true` is more surprising, just that we've (perhaps by being bitten by it early on) gotten used to it.
- redditor98654 2y agoYeah, but should that math equivalence hold for programming though? Programming is different. x=x+1 is perfectly legal in programming but does not make sense in algebra math and could confuse mathematicians.
- lordnacho 2y agoMaybe = should actually be := which it is in some languages? x = x + 1 sounds wrong if you are in math mode x := x + 1 is uncommon in math and you can take it to mean "set x to whatever is currently x, plus one" But it's also true that you need to be able to accept certain conventions when changing fields.
- Ukv 2y ago> should that math equivalence hold for programming though? It's not a hard rule that overrides all other considerations, but I do think Python's choice to follow math is the right decision here. I'd claim if you teach someone `<` then show them `5 < x < 10` for the first time, they're far more likely to go with the math interpretation than the C one. That is, beyond the fact that someone's familiarity with math reinforces this intepretation, the reason for math using this interpretation in the first place is because it aligns with intuition. It's also just pretty useful. It's common to want to check if a number is between some bounds, like `0 <= i < len`, or that multiple things are equal. In cases where you really do want the C behavior, I'd say you should already write that as `(x == y) == z` for clarity anyway, regardless of whether the language lacks chaining and thus lets you omit the parentheses.