def f(x):
regular_thing(x)
f(v)
…becomes this: def f(x):
if condition(x):
special_thing(x)
regular_thing(x)
f(v) # in the old code
f(w) # in some new code
Whereas I posit that the correct way to handle the special thing is as follows: def f(x):
regular_thing(x)
f(v)
if condition(w):
special_thing(w)
f(w)
When junior programmers insist on handling conditional execution paths further and further down the stack you end up with a plethora of optional flags being passed down through each function call.I found one piece of code where a team had given up and were passing the same **kwargs glob down three of four levels of function calls, with each function doing special conditional steps based on what it saw in the kwargs, effectively a global set of flags controlling logic up and down the stack.
It’s a great example of why long functions are a bad code smell.