Coding style
Antoon Pardon
apardon at forel.vub.ac.be
Thu Jul 20 04:50:44 EDT 2006
On 2006-07-19, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On 19 Jul 2006 12:27:39 GMT, Antoon Pardon <apardon at forel.vub.ac.be>
> declaimed the following in comp.lang.python:
>
>
>>
>> I once had a producer consumer code. When the client asked whether new
>> items were available the function could return three different values
>>
>> 1) a list with items, to be consumed
>> 2) an empty list (meaning there were no items available for the
>> moment but there could be in the future
>> 3) None (meaning the producer was done)
>>
> You have a documented interface with a tri-state return... For this
> situation, you would need the explicit test... I'd probably end up with
> something like
>
> while True:
> retrn = function()
> if retrn is None:
> break
> elif retrn:
> consume
The problem is how people here react:
Suppose I have the following kind of code:
while True:
try:
if len(result) > 0:
foo()
else
bar()
except TypeError:
break
This code makes the distinction between the three possibilities,
whether it is a good way or not I won't discuss, this is just
meant as an illustration.
Now I have a problem with the code between the if and else, so
I come to the newsgroup and post something like:
I have a problem with the following kind of code, it seems
to do blob, but I would have expected blib.
if len(result) > 0:
foo()
else:
...
And before you know it someone will respond that I shouldn't
use
if len(result) > 0:
but should just use:
if result:
Which isn't at all helpfull with my original problem, but would
be wrong in the context where the code is actually used.
--
Antoon Pardon
More information about the Python-list
mailing list