For review: PEP 308 - If-then-else expression
Jp Calderone
exarkun at intarweb.us
Sat Feb 8 15:53:35 EST 2003
On Sat, Feb 08, 2003 at 03:14:20PM +0000, Dale Strickland-Clark wrote:
> 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.
>
No, it's what structured program is *all* *about*. Picking useful pieces
of behavior out and abstracting them (often with a function). Furthermore,
say you make a mistake (unlikely in *this* trivial case, I admit). Do you
want to fix it in one place, the condsqrt function definition, or in 30
places, in 15 different source files?
No, splitting algorithms up is a very *good* idea.
Jp
--
Seduced, shaggy Samson snored.
She scissored short. Sorely shorn,
Soon shackled slave, Samson sighed,
Silently scheming,
Sightlessly seeking
Some savage, spectacular suicide.
-- Stanislaw Lem, "Cyberiad"
--
up 0:28, 7 users, load average: 0.09, 0.07, 0.09
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20030208/f714e0f1/attachment.sig>
More information about the Python-list
mailing list