samedi 18 juin 2022

Assigning function output to many variables: good or bad practice

Is it an unusual design pattern to assign output of function to many variables? Imagine each variable below representing complex data, such as nested dictionaries.

def step_1():
    a = ...
    ...
    i = ...

    return a, b, c, d, e, f, g, h, i

def step_2(a, b, c, d, e, f):
    ...
    return j
    
def step_3(g, h, i, j):
    ...
    return k


a, b, c, d, e, f, g, h, i = step_1()
j = step_2(a, b, c, d, e, f)
k = step_3(g, h, i, j)
# do something with k

Somehow it feels odd doing things like

a, b, c, d, e, f, g, h, i = step_1() or

return a, b, c, d, e, f, g, h, i or

j = step_2(a, b, c, d, e, f).

Aucun commentaire:

Enregistrer un commentaire