On 2006-07-19, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On 19 Jul 2006 12:27:39 GMT, Antoon Pardon <[EMAIL PROTECTED]>
> 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
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to