Liste des Groupes | Revenir à cl c |
David Brown <david.brown@hesbynett.no> writes:On 07/06/2024 05:53, Keith Thompson wrote:[...]
You helpfully quoted from that study, and it included :There is also the C++ compatibility question. C++ provides flexibleI mentioned earlier that someone did a study of open source C++ code and
operator overloading combined with a poverty of available operators,
so the relational operators <, >, <= and >= are sometimes used for
completely different purposes, similar to the >> and <<
operators. Chaining relational operators would complicate this
significantly, I think. If C++ adopted the feature it would be a mess
to support overloading, and if they did not, "a < b < c" in C and C++
would be valid but with completely different semantics. Neither
option is good.
found no occurrences of things like "a < b < c", except for 4 cases that
were intended to be chained but would behave incorrectly. I presume
that this study would have covered overloaded operators.
If "c" is a boolean, some might think the "natural" interpretation of "a == b == c" is "(a == b) == c" - it is the current semantics in C. Some people may think that "a != b != c" should be interpreted as "(a != b) & (b != c) & (a != c)".To me, this possibility, along with the confusion it would cause,I agree. I wouldn't mind being able to use the feature, and I think
totally outweighs any potential convenience of chained comparisons. I
have never found them helpful in Python coding, and I can't imagine
them being of any interest in my C code.
I've actually used it in Python, but its lack isn't a big problem.
Even in a new language, I would not want to see chained relationalIn Python, all comparison operators (<, >, ==, >=, <=, !=, is, is not,
operators unless you had a strict requirement that relational
operators evaluate to a boolean type with no support for relational
operators between booleans, and no support for comparison or other
operators between booleans and other types.
in, not in) have the same precedence, and chained operations are
specified straightforwardly. They evaluate to a bool result. Boolean
values can be compared (False < True), which doesn't seem to cause any
problems.
https://docs.python.org/3/reference/expressions.html#comparisons
And even then, what is "a"a == b && b == c", and "a != b && b != c", respectively, except that b
== b == c" supposed to mean, or "a != b != c" ?
is only evaluated once.
Les messages affichés proviennent d'usenet.