Rant (was Re: x*x if x>10

Diez B. Roggisch deets at nospam.web.de
Sun Jul 27 17:42:41 EDT 2008


Terry Reedy schrieb:
> 
> 
> DaveM wrote:
>> On Sun, 27 Jul 2008 19:46:32 +0200, "Diez B. Roggisch" 
>> <deets at nospam.web.de>
>> wrote:
>>> As a rule of thumb, don't return objects you didn't create inside a 
>>> function from scratch.
> 
> Unless its job is specifically to get/fetch an object (reference 
> thereto) from someplace the caller cannot or should not access.  But 
> then it should probably not mutate the object before returning the 
> reference.

I maybe should paraphrase "don't return objects you passed as arguments 
from a function". Of course there are exceptions to this rule - but 
these are few, the canonical being chained function calls like this:


class Whatever(object):

    def do_something(self, arguments):
        ....
        return self



Diez



More information about the Python-list mailing list