Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75321

Re: one to many (passing variables)

From Terry Reedy <tjreedy@udel.edu>
Subject Re: one to many (passing variables)
Date 2014-07-28 15:29 -0400
References <CAHXoDSB+-Vkggfd57nb9eLSK7Pb_fbuycGTJZM=+6=4VZo3F0w@mail.gmail.com> <8561innkmw.fsf@benfinney.id.au> <53D308CB.8030900@cdreimer.com>
Newsgroups comp.lang.python
Message-ID <mailman.12393.1406575758.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 7/25/2014 9:47 PM, C.D. Reimer wrote:
>
> On 7/24/2014 2:58 AM, Ben Finney wrote:
>> Here is an article on good API design; the principles apply to Python
>> <URL:http://blog.isnotworking.com/2007/05/api-design-guidelines.html>.
>> You know your API and its requirements better than we; see whether that
>> sheds any light on improvements to make.
> Thank you for the link. I'm curious about one item mentioned in the
> article: "Avoid return values that Demand Exceptional Processing: return
> zero-length array or empty collection, not null"
>
> Isn't a zero-length array, empty collection and null all the same thing?

No. [] is an empty list, None is a null.

> Or does the "Demand Exceptional Processing" comes from testing to see if
> the object is empty versus being null?

Testing whether null or not.

> And does this apply to Python?

Yes. If a function always returns a iterable, sometimes empty, it can be 
used as follows:

for item in f(): process(item)

If the iterable is empty, nothing happens.  If the function returns None 
instead of empty, then the use has to write the following to get the 
same result.

result = f()
if result is not None:
   for item in f(): process(item)

The function user may *elect* to give special processing to empty 
iterables.  A None return *demands* special processing, even if not 
needed, as above.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: one to many (passing variables) Terry Reedy <tjreedy@udel.edu> - 2014-07-28 15:29 -0400
  Re: one to many (passing variables) CHIN Dihedral <dihedral88888@gmail.com> - 2014-07-28 15:20 -0700

csiph-web