PEP308: Yet another syntax proposal

Andrew Dalke adalke at mindspring.com
Mon Feb 10 13:48:12 EST 2003


Aahz:
> You're missing the point.  How frequently does this occur such that
> getting all our knickers in a twist is worth it?  So far, most of the
> examples pushing a conditional expression have *NOT* required
> short-circut behavior.  For the cases where side-effects restrict the
> use of a conditional expression, I think perhaps requiring the use of an
> if statement is the most appropriate way to handle it.

Extroplating from my earlier analysis, previously I noted that the
if/else expression will be used appropriately about 1 in every 1,000
lines of Python code.  (Based upon inspection of existing C, C++,
and Python code.)

As I recall, nearly all cases (perhaps 9 of 10) did not involve
a case where short-circuiting was relevant -- both sides of the
expression could be evalutated without side effect.  In addtition,
in a majority of those cases (perhaps 3 in 4) the branches were
constant, as in a simple number or string, so there is very little
performance gain.

That suggests that short circuiting if/else expression will be used
appropriately about once every 4,000 to 10,000 lines of Python
code.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list