5 ms·
State machines implemented with gotos have very clearly defined regions for each state: the space between each label. Switch-based state machines are fine, but
by colanderman 8y ago
State machines implemented with gotos have very clearly defined regions for each state: the space between each label. Switch-based state machines are fine, but become hard to follow when e.g. you need a loop around a couple states, and are often abused to allow changing states from a non-lexically-local context (e.g. within a function call).
At a high level, this:
goto NewState;
is no less comprehensible or spaghetti-prone than this:
state = NEW_STATE;
break;
- kbumsik 8y agoThat’s what I am thinking of. These days people use goto only to reduce spaghetti code in very specific use cases in C and nothing more.