Conditional Expressions don't solve the problem

Carl Banks idot at vt.edu
Wed Oct 17 14:07:27 EDT 2001


Paul Rubin <phr-n2001d at nightsong.com> wrote:
>
> But it's not just saving keystrokes--the usual place for an assigment
> in an expression is in the control expression for a while loop.
> Having to split it into several statements clutters up the code and
> makes the readability WORSE by moving the test condition away from the
> 'while' keyword.  Do you REALLY find
> 
>     while (line := file.readline()) != 'end':
>         process_line(line)
> 
> to be less readable than
> 
>     while 1:
>        line = file.readline
>        if line == 'end': break
>        process_line (line)
> 
> (or worse, imagine several nested loops like that)?  I don't.

I do.

I find assignment within an expression to be contrived and opaque.  I
would be surprised if there were many of your opinion who weren't
numbed down to it by years of exposure to C.


-- 
CARL BANKS



More information about the Python-list mailing list