For review: PEP 308 - If-then-else expression
William Park
opengeometry at yahoo.ca
Sun Feb 9 02:43:23 EST 2003
Jp Calderone <exarkun at intarweb.us> wrote:
>> >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.
To a certain point. For the silly example above,
(z>0.0) ? sqrt (z) : 0.0
would do nicely.
--
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
Linux solution for data management and processing.
More information about the Python-list
mailing list