PEP 308: some candidate uses cases from live code
Steve Holden
sholden at holdenweb.com
Mon Feb 10 17:17:01 EST 2003
"Andrew Koenig" <ark at research.att.com> wrote in message
news:mailman.1044904116.31652.python-list at python.org...
> 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
>
>
> because it doesn't look like anything new.
>
However, it clearly introduces new precedence problems into the syntax: how
do I know you meant
self.stream.writeln("Ran %d test%s in %.3fs" %
(run, (if run==1: "" else: "s"), timeTaken)
and not (apart from the run-time error it would produce)
self.stream.writeln("Ran %d test%s in %.3fs" %
(run, if run==1: "" else: ("s", timeTaken))
Methinks anything that allows colons inside expressions will be tough for us
to read.
> 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.
>
This isn;t the only area where people like to make things tougher for
themselves than they need really be. Some people would shoot themselves in
the foot even if they only had a pitchfork :-) (present company excluded,
naturally).
> 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.
>
I quite agree.
regards
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
Register for PyCon now! http://www.python.org/pycon/reg.html
More information about the Python-list
mailing list