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
--
https://mail.python.org/mailman/listinfo/python-list