
Don’t Use Boolean Arguments, Use Enums - anupamchugh
https://medium.com/better-programming/dont-use-boolean-arguments-use-enums-c7cd7ab1876a
======
uberman
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
The 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.

