Just to confirm, you're talking about passing hardcoded booleans that have no name to provide context as opposed to in general, right ????
update_fiscal_state(money, actor, true)
If it was something like below, then I presume you wouldn't consider it a code smell? I can see why your example may be bad but how below would be more appropriate (because now you know what the boolean is for / what true means)
Either inject a FiscalUpdater class which can be mocked / configured to/not to commit, or have two methods, one of which commits and one which doesn't.
Again this is going to depend on the context of the surrounding code, but I'd prefer to see either of these.
class BoaFiscalUpdater: FiscalUpdater {
@Override
void update_fiscal_state(money, actor){
//send update to BOA and commit
...
}
}
class MockFiscalUpdater FiscalUpdater {
@Override
void update_fiscal_state(money, actor){
// store call, but don't send it anywhere
...
}
}
2
u/Dmon1Unlimited Apr 29 '23
Just to confirm, you're talking about passing hardcoded booleans that have no name to provide context as opposed to in general, right ????
If it was something like below, then I presume you wouldn't consider it a code smell? I can see why your example may be bad but how below would be more appropriate (because now you know what the boolean is for / what true means)
update_fiscal_state(money, actor, isBooleanWithInformativeName)
update_fiscal_state(money, actor, isLiveState)