3 ms·
State machines and actors are occasionally cited as good ideas here, and they seem like much the same kind of unstructured programming IME.
by lmm 5y ago
State machines and actors are occasionally cited as good ideas here, and they seem like much the same kind of unstructured programming IME.
- m_mueller 5y agoWhy? You can easily emulate a state machine with a while loop, a switch case and one more level of if-branches. Abstracting those in a framework doesn't make it unstructured IMO.
- lmm 5y ago> You can easily emulate a state machine with a while loop, a switch case and one more level of if-branches. You can easily emulate GOTO much the same way.
- m_mueller 5y agoobviously, as long as the language is turing complete, but you just converted an unstructured program to a structured one.
- maskros 5y agoAnd gained nothing except more verbose syntax. The goto spaghetti is still spaghetti whether you use "goto" or "switch".
- m_mueller 5y agoDisagree. You eliminate backward gotos except for the while loop, which is much more clearly communicating the way to extend the code (by adding more states or state transitions) to the next person taking over. I‘m not categorically against goto in certain contexts (like C based systems programming), but IMO backwards jumps with goto need to be eliminated.
- lmm 5y agoTo the same extent, and in the same way, as you did when you converted a state machine the same way? I still don't get what distinction you're drawing between state machine style and GOTO style.
- zozbot234 5y agoIndeed, GO TO is not that unstructured; it can be said to have a fairly precise semantics of "sets the continuation of the program to <label>; does not proceed to the next statement.". Though if you want to analyze the semantics of a GO TO-using program, it's practically a required step to endow all of your labels with appropriate COME FROM annotations, marking the branches it could be reached from - and that's a whole-program analysis, at least in principle. That's the point where you're giving up modularity!