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


Groups > comp.lang.python > #75321 > unrolled thread

Re: one to many (passing variables)

Started byTerry Reedy <tjreedy@udel.edu>
First post2014-07-28 15:29 -0400
Last post2014-07-28 15:20 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#75321 — Re: one to many (passing variables)

FromTerry Reedy <tjreedy@udel.edu>
Date2014-07-28 15:29 -0400
SubjectRe: one to many (passing variables)
Message-ID<mailman.12393.1406575758.18130.python-list@python.org>
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

[toc] | [next] | [standalone]


#75332

FromCHIN Dihedral <dihedral88888@gmail.com>
Date2014-07-28 15:20 -0700
Message-ID<3af1eb8d-dada-4d6c-8d3f-3f2f1c7c6335@googlegroups.com>
In reply to#75321
On Tuesday, July 29, 2014 3:29:04 AM UTC+8, Terry Reedy wrote:
> 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

Oh, iterators are better to shoot 
targets in the L1 and L2 cache memory,
but it is not  the same as the old
 reading the whole list way.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web