Let me clarify my question. I've found myself not know what to choose in the following scenarios
Scenario 1 - Function that modifies an array (or other mutable object)
Option 1: Modify array in function and return it.
def double(arr):
arr = 2*arr
return arr
def main:
# do stuff
arr = np.array([1, 2, 3])
arr = double(arr)
# do more stuff
Option 2: Modify array in place
def double(arr):
arr = 2*arr
def main:
# do stuff
arr = np.array([1, 2, 3])
double(arr)
# do more stuff
Scenario 2 - Class method which uses class property
Option 1: Pass class property as parameter
class Class():
def __init__(property):
self.property = property
def main():
result = calculate(self.property)
return result
def calculate(property):
# do stuff with property
return result
Option 2: Just reference the property directly
class Class():
def __init__(property):
self.property = property
def main():
result = calculate()
return result
def calculate():
# do stuff with self.property
return result
I can think of some cases where the choice is clear but just wondering if there are some rules of thumb or common practices.
I would like to get answers with reputable references if possible as I know this type of topic can be very opinion driven.