code review
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sun Jul 1 21:26:57 EDT 2012
On Sun, 01 Jul 2012 05:55:24 -0400, Terry Reedy wrote:
> On 7/1/2012 2:54 AM, Steven D'Aprano wrote:
>
>> So no, Python has always included chained comparisons, and yes, it is
>> shameful that a language would force you to unlearn standard notation
>> in favour of a foolish consistency with other operators. Comparisons
>> aren't special because they return bools. They are special because of
>> the way they are used.
>>
>> C treats comparison operators as if they were arithmetic operators, and
>> so the behaviour of a chained comparison is the same as the behaviour
>> as a sequence of arithmetic operators: a foolish consistency. Python
>> treats comparison operators as comparison operators, and gives them
>> behaviour appropriate to comparisons.
>
> I considered this a great feature of Python when I first learned it.
> Reading about how rare it is among programming languages to treat
> comparisons in the standard way in mathematics reinforces that.
Apart from Python, Mathematica, Perl 6, CoffeeScript, Cobra and Clay give
chained comparisons the standard meaning. It is, or was, a feature
request for Boo, but I can't tell whether it has been implemented or not.
C-like semantics are next to useless, except perhaps for obfuscation:
http://stackoverflow.com/questions/4089284/why-does-0-5-3-return-true/
And surprising:
http://answers.yahoo.com/question/index?qid=20090923172909AA4O9Hx
C-like semantics are a clear case of purity of implementation overruling
functional usefulness.
--
Steven
More information about the Python-list
mailing list