one to many (passing variables)

CHIN Dihedral dihedral88888 at gmail.com
Tue Jul 29 00:20:12 CEST 2014


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.



More information about the Python-list mailing list