PEP 308: some candidate uses cases from live code

Erik Max Francis max at alcyone.com
Mon Feb 10 22:58:45 EST 2003


Andrew Dalke wrote:

> Andrew Koenig:
>
> > Here's an example from the Python 2.2.2 distribution,
> > Lib/unittest.py,
> > lines 618-619:
> >
> >         self.stream.writeln("Ran %d test%s in %.3fs" %
> >                            (run, run == 1 and "" or "s", timeTaken))
> >
> > Need I say more?
> 
> Care to make any comments about the use of the non-standard
> and Pascal-like "writeln" instead of using the much more standard
> "write" with a "\n" at the end of the string?

That's a stylistic issue.  We're talking about a _bug_ that someone
introduce because they trusted a conditional operator-like idiom too
much.

> Are other parts of the code written as if by someone with
> more experience in some language other than Python?  Could that
> experience have cause them to want a "?: by any means" rather
> than using a more traditional approach?

The point here is that this validates what Andrew and others (including
myself) have been saying all along:  People want a conditional operator
bad enough that they use pale comparisons, and those comparisons have
flaws.  People who use the `C and x or y' idiom may do so without
understanding those limitations, and that will lead to bugs.

Here he has proof of this not just theoretically, not just in random
code in the world, but in the standard library itself!

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Ride / Ride this wave of mine
\__/ Res
    Esperanto reference / http://www.alcyone.com/max/lang/esperanto/
 An Esperanto reference for English speakers.




More information about the Python-list mailing list