For review: PEP 308 - If-then-else expression

Tim Peters tim.one at comcast.net
Mon Feb 10 12:56:21 EST 2003


[Andrew Koenig]
> ...
> Finally,
>
> 4) in SearchDialog.py:
>
>             text.mark_set("insert", self.engine.isback() and
> first or last)
>
> It is not possible to determine by inspection whether this code is
> correct.  Its correctness depends on proving that whenever
> self.engine.isback() is true, first is also true (i.e. not zero, not
> empty, etc.)
>
> It turns out that this code is correct, but to show it, I had to hunt
> back 12 lines to find
>
>      first = "%d.%d" % (line, i)

Its correctness is obvious to people who actually work on SearchDialog.py,
because they know what the code does -- arguments to mark_set() have to be
"location strings" as Tk defines that term, and an empty string doesn't make
sense in that context.

> I didn't actually expect it to be easy to find examples in distributed
> python code that were provably incorrect.  However, I also did not
> expect it to be this easy to find examples that were not obviously
> correct.

Well, if you try to prove that a piece of code is correct when you don't
understand what it does, it's going to be very easy indeed to find "not
obvious" stuff.  What's more surprising to me is that you found half the
instances obvious despite not knowing the code's intent <wink>.






More information about the Python-list mailing list