PEP308: Yet another syntax proposal

Andrew Dalke adalke at
Tue Feb 11 21:34:37 CET 2003

James J. Besemer:
> Can you enumerate those negative consequences and quantify their cost some

Did you not see all my posts on just this subject?

Andrew Koenig analyzed his C codebase for use of ?:.  He described
if the use of ?: was appropriate or not.  I then translated the use to
code and pointed out that in some cases there was a more readable
alternative.  (And no, [false, true][bool(exp)] is not considered readable
in my book).

I analyzed a C++ code base and noticed the high number of misuses of
the ?: operator in it.  I also noted that many of those cases disappear in
Python, partially because Python has the min/max function (many of the
cases were just to get the min/max of two values).

Someone else (forgot who - my apologies!) did a very nice analysis of
his Python code looking for where the if/else expression could be used,
vs. where it should be used, and noted that those two were not the same.
(Eg, the PEP 308 case was less readable for some cases involving
long lines)

Given these numbers, I could estimate the frequency of PEP 308
use were it put into place.

I then assigned a probability that someone would use an if/else expression
rather than use a more appropriate Python idiom (eg, from lack of
experience with Python idioms like "x = y or default") or because of
a desire to fit things into a single line because it's "terse" rather than
being readable.  These numbers were made up, but I think not entirely
unreasonable.  These were used to determine the likelihood of proper
use vs. improper use.

Combining the different analysis, I then determined that the ballpark
estimates of use are:

   - The if/else expression could be used about once every 400 lines
   - The if/else expression will be used about once every 1,000 lines
   - The if/else expression with short-circuiting is needed only about
       once every 5,000 lines (given other Python idioms)

And the rates of misuse range between 1 misuse for every 1
appropriate use, and 1 misuse for every 3 appropriate uses.

                    dalke at

More information about the Python-list mailing list