Bad:
my_parameter = ...
def function1(...):
# uses my_parameter
return ...
def function2(...):
# uses my_parameter
return ...
Better:
def get_my_parameter():
...
return my_parameter
def function1(my_parameter, ...):
# uses my_parameter
return ...
def function2(my_parameter, ...):
# uses my_parameter
return ...
Discuss where the state is located in the two above examples.
Bad:
def does_a_or_b(..., option_b=False):
return ...
Better:
def does_a(...):
return ...
def does_b(...):
return ...
Introduce testing early as a safeguard.
Use code coverage analysis tools.
Cut the code at important interfaces.
Build and test modules separately to identify hidden dependencies.