4 ms·
The way I’ve seen this dealt with in objective C, and I use this pattern in JavaScript, is to make a new function with the additional arguments, and then refact
by whiddershins 6y ago
The way I’ve seen this dealt with in objective C, and I use this pattern in JavaScript, is to make a new function with the additional arguments, and then refactor the old function to be a convenience function that calls the new function and passes defaults to the new parameters.
Original function:
doSomething(foo){
*body*
}
Refactored functions:
doNewSomething(foo, bar){
*body*
}
//now a convenience function
doSomething(foo){
bar = defaultValue;
doNewSomething(foo, bar);
}
Doesn’t this solve this when updating a library?
- Noumenon72 6y agoSo when I look up `toReadableNumber(num, base = 10)` in the current library documentation and pass it binary 11001010, in your codebase I get '11,001,010' instead of 202.
- whiddershins 6y agoWait, what? Like if you only pass one variable, you get the old behavior, and to pass two variables you have to call a new function name. What am I misunderstanding about what you are writing.
- whiddershins 6y agoso you would have a new function called toReadableNumberWithBase(num, base)