code review

Thomas Jollans t at
Sun Jul 1 09:46:56 CEST 2012

On 07/01/2012 09:28 AM, Ben Finney wrote:
> Chris Angelico <rosuav at> writes:
>> On Sun, Jul 1, 2012 at 10:08 AM, Ben Finney <ben+python at> wrote:
>>> Thomas Jollans <t at> writes:
>>>> My sole point, really, is that "normally", one would expect these two
>>>> expressions to be equivalent:
>>>> a < b < c
>>>> (a < b) < c
>>> What norm gives you that expectation? That's not how those operators
>>> work in mathematical notation. I know of no programming language
>>> that would give a newcomer to Python that expectation. So where is
>>> the norm you're referring to?
>> C, SQL, REXX, and many other languages.
> So, languages without strong typing then. In that case, I revise my
> statement: I know of no programming language with strong typing that
> would give a newcomer to Python the above expectation.
> Since Python does have strong typing, norms about operations from
> weakly-typed languages should not be expected to apply.
> (Incidentally, PostgreSQL was the SQL implementation I went to, and::
>     postgres=# SELECT (1 < 2) < 3;
>     ERROR:  operator does not exist: boolean < integer
>     LINE 1: SELECT (1 < 2) < 3;
>                            ^
>     HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
> So not all SQL implementations make the mistake of weak typing.)

I don't have PostgeSQL handy just now - what is the result of
(1 < 2 < 3) ? I bet it's the same error, which means the two are still

Look through the part of this thread about languages, and you will see
how unique Python is in this regard. You argument about strong typing
doesn't really hold: in Python, as in some other languages, bool is an
integer type, so it can actually be compared to numbers, so even if
Python used the same rules as Java, chaining comparison operators would
still be valid syntax (if a little silly in most cases)

More information about the Python-list mailing list