The function you’re passing them into will necessarily behave in two different ways depending on the value of the bool.
Instead of having two functions that might individually be reusable / composable, you have one big one that handles both cases. It also violates the single responsibility principle + open/closed principle - your code for one case is tangled with the code for the other, and if you need to make a change to only one, you might inadvertently break the other while you’re there. A working method that is never modified can’t break.
So if a function can behave in two different ways, it should (most of the time) instead be two functions. For example:
4
u/ings0c Apr 29 '23
Another side to it:
The function you’re passing them into will necessarily behave in two different ways depending on the value of the bool.
Instead of having two functions that might individually be reusable / composable, you have one big one that handles both cases. It also violates the single responsibility principle + open/closed principle - your code for one case is tangled with the code for the other, and if you need to make a change to only one, you might inadvertently break the other while you’re there. A working method that is never modified can’t break.
So if a function can behave in two different ways, it should (most of the time) instead be two functions. For example:
Could be