List mutation method gotcha - How well known?

L

Lie

I expect functions with no documentation of what they return to return
`None`.  Assuming they are documented at all, of course.  :)

It's like not writing a ``return`` statement in the code: there's always an
implicit ``return None`` at the end of every function.

I personally won't to rely on it. Sometimes a return statement might
be documented, but not complete enough, like this:

def genericadd(a, b):
"""
Adds two number, returns the same as longadd if
either operands are long type and returns the same
as intadd if all operands are int type.
<ommiting documentation about what would happen if
either type are neither long nor int by negligence>
"""
if isinstance(a, long) or isinstance(b, long):
return longadd(a, b)
if isinstance(a, int) and isinstance(b, int):
return intadd(a, b)
return "Error"

This function is written badly on purpose to simulate what a less-than-
intelligent programmer might write, which is in no control of ours as
a class user.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top