Question

i'm creating a function() but this func() is getting bigger so i need to break it down into smaller part. here's the illustration :

def myfunc(x,y,z):
    out=(x*y*z)+ val
    return out

a,b,c=1,2,3
A=myfunc(a,b,c)
print A

let say i want to separate (break down) the (x*y*z) into another function like this :

def myotherfunc(x,y,z):
    return x*y*z

def myfunc(x,y,z):
    out=myotherfunc(x,y,z) + val
    return out

That is a simple breakdown, but i got another workflow as follow :

def myotherfunc(x,y,z)
    return x*y*z

def myfunc(xx):
    out=xx+val
    return out

a,b,c=1,2,3
A=myfunc( myotherfunc(a,b,c) )
print A

Same result, but for more complex programming case, which is preferable workflow ? and why ?

Était-ce utile?

La solution

The answer should also depend on (potential) reuse: is it likely, e.g., that myotherfunc would in the future be called with more than three parameters? if so, prefer option 2.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top