3 ms·
Fixing an ambiguous function by converting boolean parameters to enumerators makes the issue worse in my opinion. The right solution (if you are refactoring an
by uberman 7y ago
Fixing an ambiguous function by converting boolean parameters to enumerators makes the issue worse in my opinion.
The right solution (if you are refactoring anyways by altering the signature) is to fix the real issue that you have, a function that is doing multiple jobs.
s setUserState() should either accept a user_state or be re-factored into state specific methods such as setUserOnline()
Using an enum if I do:
setUserState(UserState.ACTIVE)
followed by
setUserState(UserStates.BLOCKED)
What is the actual user state? Is it "blocked" or is it "active and blocked"? At least with the series of booleans, that would be made clearer.
- anupamchugh 7y agoThe whole point of the piece was to avoid a series of booleans in function arguments. Active and Blocked isn't really a scenario I've seen anywhere. Use enums when the states are mutually exclusive is what I'd like to reinstate.