I am experiencing a dilemma. Let me explain it with two functions:
# Takes vector.magnitude(), vector.x, vector.y and uses it somewhere
def func1(vector, {other parameters 1}):
pass
# Takes vector.magnitude(), vector.x, vector.y and uses it somewhere
def func2(vector, {other parameters 2}):
It is not uncommon that func2
is called right after func1
with the same vector
variable. There is a redundant calculation for the vector magnitude, as it is calculated twice. Should the vector magnitude instead be a separate function parameter? If not, what should be changed to alleviate this problem?