Instance attributes vs method arguments

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Tue Nov 25 22:07:41 EST 2008


On Tue, 25 Nov 2008 10:21:18 +0100, M.-A. Lemburg wrote:

> It is always good practice to provide default values for instance
> variables in the class definition, both to enhance readability and to
> allow adding documentation regarding the variables, e.g.
> 
> class Class_a:
> 
>    # Foo bar
>    a = None
> 
>    # Foo baz
>    b = None

"Always"?


I would question that. If the instance attribute is always set, then the 
class attribute is just noise. It's not *wrong* exactly, but it is 
redundant. The documentation point is worthwhile, but I would say it is 
in the wrong place: it should be documented in the class docstring, not 
the source code.


-- 
Steven



More information about the Python-list mailing list