Q about tail recursion

Tim Peters tim_one at email.msn.com
Sun Feb 27 09:22:05 CET 2000


org
[François Pinard]
> By the way, I sometimes hesitate at having an explicit:
>
>         return None
>
> as the last line of a function.  I guess I usually give in
> writing it, would it be only as some kind of documentation, but
> then (being anal myself :-) I would consider as a style bug not
> doing it always, if I do it sometimes.  (It would of course always
> be OK _not_ writing that line for `def's not meant to return a
> usable value.)
>
> I wonder a bit.  Is there any common wisdom about this detail?

I think you've already divined it:  if a def is really "a procedure" (never
"meant to return a usable value"), never code "return None".  If a def is
really "a function" (always "meant to return a usable value"), always code
"return None" on any path where you intend to return None, and even consider
putting "assert 0" at the end of the function if you never expect to "fall
off the end".  And if a def is sometimes meant to return a value and
sometimes not, redesign the code before you drive yourself insane <wink>.

rigidity-is-freedom-ly y'rs  - tim






More information about the Python-list mailing list