Suppose I have a function
f that uses two helper functions
g to get the job done. There are two possible ways of dealing with this situation.
(1) take explicit arguments and returns new objects from each helper function:
def f(x): def h(x): <do something> return y def g(y): <do something else> return z return g(h(x)) \\ x remains unchanged
(2) use the scope of
f to access and mutate the original argument until it is at the desired state:
def f(x): def h(): <do something> def g(): <do something else> h() g() return x \\ x is now different
I like situation (1) because it think it is easier to understand what is happening, but I don't really have any concrete reasons for why (1) is better other than it makes more sense to me.
What is the right way to think about this?