I often have functions which take a parameter, set an instance variable to that parameter, and then do other things, e.g.:
def updateFoo(self, foo):
self.foo = foo
fooProcessor1(foo)
fooProcessor2(self.foo)
Do you prefer to pass the parameter itself, as in fooProcessor1, or the newly-set instance variable, as in fooProcessor2? Why or why not?
A function named
setFoo()really shouldn’t do anything more than settingfoounless it is computing and caching a value derived from foo, in which case I would advise something along the lines of:Of the options you suggested, I prefer
fooProcessor1(foo). That said, it is mostly a matter of personal preference. As long as you are consistent, I don’t think it matters all that much.