Style question: 'return None' vs 'pass' in do-nothing methods?

Hans Nowak wurmy at earthlink.net
Tue Jan 8 19:00:26 EST 2002


"Elf M. Sternberg" wrote:
> 
>         I'm using Webware for a project and noticed that in version 0.6
> Chuck finally included support for cascading style sheets.  I had put my
> own support into the project I was working on, and I notice that there
> seems to be a stylistic difference between what he did and what I did.
> For pages that don't need it (such as redirects), I defined it as:
> 
> def stylesheet(self):
>         return None
> 
> Whereas Webware used:
> 
> def writeStyleSheet(self):
>         pass
> 
>         Is there a reason for favoring one over the other?

To me, a definition like

    def f(self):
        pass

has a connotation of an abstract method, a method that is just
there to be overridden but that doesn't do anything in the
current class, or a method that has not been implemented yet
(if the program is a work in progress).

    def f(self):
        return None

lacks this, IMHO; it seems to return None explicitly, for a
reason. 

Of course, everybody's mileage may vary... but this I how
I personally would use these constructs.

--Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==') 
       # decode for email address ;-)
Site:: http://www.awaretek.com/nowak/



More information about the Python-list mailing list