I have this function f(MyType a, b) and I want to it to become f(MyType a, b, c). The problem is that f is called by multiple other functions (g(), h(), i()) which in turn are called by multiple other functions. I would need to pass the new argument int c down to all functions so they can pass it to f().
I would like this:
int f(TypeA a, TypeB b);
int g(TypeA a, TypeB b) {
f(a, b);
}
int r(TypeA a, TypeB b) {
g(a, b);
}
To become this:
int f(TypeA a, TypeB b, TypeC c);
int g(TypeA a, TypeB b, TypeC c) {
f(a, b, c);
}
int r(TypeA a, TypeB b, TypeC c) {
g(a, b, c);
}
How could I automate this? Is there any other elegant solution I'm not seeing?
Global mutable state is undesirable. I've considered creating a singleton class with setters and getters to avoid any unwanted side effects but MyType is already used in a lot of places and I would need to refactor those instead.
coptional by providing a default value?MyType chas to be initialized from command line arguments and 'f()` always needs it. There is no meaningful default value I could provide.a,b, andc. Then, if you need to adddlater it needs to be done in only one place. When the initial design proves to be unworkable, there is no alternative to paying the price and redesigning everything from scratch.