PEP 308: some candidate uses cases from live code

Andrew Koenig ark at research.att.com
Mon Feb 10 14:06:40 EST 2003


holger> I have seen worse effects of buggy code than this.   
holger> Besides, in a PEP-308 world you would certainly find the like of

holger>    self.stream.writeln("Ran %d test%s in %.3fs" %
holger>                       (run, 's' if run==1 else '', timeTaken)

holger> Getting things messed up with ternary ops (whichever) is easy enough.
holger> That doesn't imply we have to introduce a new one. 

Indeed.  That's part of the reason I now favor

    self.stream.writeln("Ran %d test%s in %.3fs" %
                       (run, if run==1: "" else: "s", timeTaken)

because it doesn't look like anything new.

Anyway, the point that I consider important is that Python
programmers--including the authors of the Python library--consider an
if-then-else construct to be useful enough that they fake it.
Moreover, they do so in ways that are somtimes just plain wrong.

I think that if having a way to write an if-then-else expression is
a bad idea, then the and/or idiom is an even worse idea because it's
unreliable.





More information about the Python-list mailing list