pep 308: why doing (almost) nothing suffices

Edward K. Ream edream at tds.net
Sun Mar 9 21:28:33 EST 2003


> > def choose_eval(cond, a, b): # warning: evals all arguments
> >
> >     if cond: return eval(a)
> >     else: return eval(b)
> >
> > Heavy duty stuff by my present bathtub standards.  So to "delay" the
> > evaluation of an argument, just quote it.  Wow--just like lithp.
>
> This was actually brought up during the PEP 308 debate.  The problem
> with it is that it doesn't do the whole tokenization and compilation
> phase at the same time; it holds some off until later.  This is a
> potential performance problemi if the choose_eval code appears in a loop,
> which it likely will find itself at some point.

Thanks for pointing this out.  However, this does not change the fact that
Python already provides more than enough tools for this job.  In those
(presumably rare) cases where performance matters, one could just use the
"if" statement. In all other cases, choose or choose_eval will be more
convenient.  Indeed, the _only_ knock on the present "if" statement is that
it is a bit clumsy.  But that is a very minor inconvenience when serious
performance issues are at stake.

This is merely my opinion, and I won't be distressed if it is ignored,
particularly since none of the other options will interfere with choose or
choose_eval.  OTOH, I think the three options (choose, choose_eval and if)
would be quite good enough if they were documented in the usual places.

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------






More information about the Python-list mailing list