Why return None?

Alex Martelli aleaxit at yahoo.com
Thu Aug 26 04:25:10 EDT 2004


Martin DeMello <martindemello at yahoo.com> wrote:
   ...
> My main point is that returning None is pretty useless - it 'wastes' the
> return value, and doesn't allow method chaining. Returning self allows
> you to either use or discard the return value depending on whether
> you're interested in it, whereas using None doesn't give you any choice.

>>> import this
The Zen of Python, by Tim Peters
   [snipped]
There should be one-- and preferably only one --obvious way to do it.


Not leaving stylistic choice (which would lead to more than one obvious
way to do it) is quite consonant with the Zen of Python.  Of course one
can't always reach what's preferable, but "your main point" which is
presumably meant as a criticism of this design choice comes across as
praise: the design choice follows the overall design's philosophy.

Guido doesn't like method chaining, so he made a design choice that did
not allow method chaining, and did not give several equally obvious ways
to perform some typical, important tasks.  This consistency between
detailed design decisions and overall philosophy is exactly that Quality
Without a Name which makes Python so great.


Alex



More information about the Python-list mailing list