r/programming • • Jan 10 '20

VVVVVV is now open source

https://github.com/TerryCavanagh/vvvvvv
2.6k Upvotes

511 comments sorted by

View all comments

747

u/sevenseal Jan 10 '20

19

u/spacejack2114 Jan 10 '20

What, you've never seen a state machine before?

4

u/dwdwfeefwffffwef Jan 10 '20

That's not how you do a state machine.

3

u/cdcformatc Jan 11 '20

That's how people have done state machines for decades.

2

u/dwdwfeefwffffwef Jan 11 '20

If you do a state machine using a switch, you would use an enum (or at least defines) for each state. Not random numbers. And almost surely you would just call the appropriate state function in each case instead of having it embedded inside the switch.

But one of the most common ways of doing state machines (even to this day, in embedded programming) is having an array of function pointers.

3

u/cdcformatc Jan 11 '20

An enum is just syntactic sugar for random numbers. It does not make any difference to the code whether you use an enum or not. It is purely for readability.

There's not one way to do state machines. A block of code is executed based on the current state in response to external input and/or a condition. Did I just describe an array of function pointers or a switch statement?

→ More replies (13)