DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,864 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in

Discussion on: Status instead of isLoading boolean?

Collapse
 
myleftshoe profile image
myleftshoe

Nice tip. And if needed you could implement a state machine.

Collapse
 
joannaotmianowska profile image
Joanna Otmianowska Author • Edited on

Thanks! Yes, that's true. But state machine would be work for better more complex status management

Collapse
 
macsikora profile image
Pragmatic Maciej

Everything is a state machine, even isLoading state with setState represents such with two possible states. The problem starts when the model needs more than two states, then bool starts to be a problem. I have few articles about this subject, take this - dev.to/macsikora/boolean-the-good-.... πŸ˜‰

Thread Thread
 
joannaotmianowska profile image
Joanna Otmianowska Author

thanks! I will check out your articles

Collapse
 
myleftshoe profile image
myleftshoe

Agreed, a state machine in this case would be overkill. Compare time and mental load to

  1. write out some if statements (virtually no mental load) vs
  2. think about representing the logic as a state machine, draw a state diagram, etc

Not only that but the code would be harder for others to grok than if statements and would make them wonder why it was implemented as a state machine - "I must be missing something"

And if you were a contractor, paid by the hour, using a state machine in this case would look like that you were milking your hours and using your time to experiment or hone your skills