[Tutor] Efficiency of Doxygen on Python vs C++?
Kent Johnson
kent37 at tds.net
Sat Aug 18 06:06:19 CEST 2007
Stephen McInerney wrote:
> I was asking if it's a recognized good programming practice to
> declare and initialize *all* members in the class defn.
What do you mean by "initialize *all* members in the class defn"? Your
original example was not syntactically correct Python. You wrote:
class C
s = []
d = {}
ot = (None, None)
If by this you meant to define all the variables at class scope:
class C:
s = []
d = {}
ot = (None, None)
then I would say emphatically no, this is not even common practice, let
alone a recognized best practice.
If you mean to initialize the variables in the __init__() method:
class C:
def __init__(self):
self.s = []
self.d = {}
self.ot = (None, None)
maybe this is more common but I don't think I have ever seen it
recommended to initialize all variables in the __init__() method.
Certainly there are times when it makes sense to have some of the
initialization in other methods that are called from __init__(). So if
by "recognized good programming practice" you mean something like
"commonly recommended" I would say no, it is not.
> I think I'm hearing a general yes on that - any other opinions?
Not sure where you think you are hearing a yes, I am hearing a lot of
objections.
Kent
More information about the Tutor
mailing list