I am working on a python project with classes that have quite a few parameters and methods. In order to reduce complexity, I have been writing the methods as such:
def foo(self):
return self.parameter1 * self.parameter2
Would it be better practice to explicitly pass the parameters?
def foo(self, parameter1, parameter2):
return parameter1 * parameter2
This comes up because I have found it difficult to test the functions in the class without testing the entire class.
self, is there a reason to put it on the class? Note that I'm not advocating that you just put all sorts of data willy-nilly in your class, or that you have your class end up as some sort of state-management nightmare ... Basically, there isn't nearly enough information here for us to make an informed recommendation :-)