For review: PEP 308 - If-then-else expression

Dale Strickland-Clark dale at riverhall.NOTHANKS.co.uk
Sat Feb 8 10:14:20 EST 2003


Anthony Baxter <anthony at interlink.com.au> wrote:

>This might be fine, but if you start getting listcomps with one of
>these ternary operators, and an if clause in the listcomp. you're 
>going to be leaving someone with a hellish ugly bit of code to read.
>
>
>Why not simply:
>
>def condsqrt(z):
>  if z > 0.0: 
>    return sqrt(z)
>  else:
>    return 0.0
>
>y = [ condsqrt(z) for z in x ]
>
>There's a function call overhead, but it's a hell of a lot easier to
>read.
>

No. Splitting an expression so it's spread over your code is a very
good way of introducing inefficiencies and bugs. And now the reader
has to hunt around looking for the function to understand what's going
on.

Very bad idea.
--
Dale Strickland-Clark
Riverhall Systems Ltd




More information about the Python-list mailing list