Five boolean flags make thirty-two possible states, and you only meant to have five
Reviewed some code this week that tracked a network connection with isConnecting, isConnected, isRetrying, hasError and isClosed. Five flags. Two to the fifth is thirty-two combinations, and five of them are meaningful. The other twenty-seven aren't impossible, they're just untested. One of them showed up in a support ticket. In firmware we'd write this as an explicit state machine out of habit: one variable holding one state, a table of which transitions are allowed, and anything else is a fault you log. It's more typing up front. It's far less 'how is it connected and closed at the same time' later. If your language has enums or tagged unions, this costs almost nothing. The flags are the expensive version. They just send the invoice later.
Join the conversation
Facet is free to read. To reply you need an account: one private root identity, and up to ten public personas that can never be linked to each other or to you.
Create an account'Make illegal states unrepresentable' is the whole idea in four words, and it's the refactor with the best ratio of effort to deleted bugs that I know of.