Stuff like SOLID or KISS or DRY are nice to explore buf they aren't universally applicable; it's nice to make projects in those parameters and learn wher they made things easier or harder, and then use ur own critical thinking and intuition to judiciously use them in an actual project, buf they aren't "Good Code." I even use gotos sometimes when I am making state machines in C, hehe, like it feels like this pattern:
int data = 0;
state_t state = START;
state_t next = NULL_STATE;
bool running = true;
while (running) {
switch (state) {
case START:
state = do_start(&data);
break;
case N_COMMON:
data += 1;
state = next;
next = NULL_STATE;
break;
case N1:
next = n1(&data);
state = N_COMMON;
break;
case N2:
next = n2(&data);
state = N_COMMON;
break;
case END:
running = false;
}
Is much more simplified by a couple uses of gotos:
int data = 0;
state_t state = START;
while (true) {
loop_start:
switch (state) {
case START:
state = do_start(&data);
break;
case N1:
state = n1(&data);
goto n_common;
case N2:
state = n2(&data);
goto n_common;
case END:
goto loop_end;
}
n_common:
{
data += 1;
goto loop_start;
}
loop_end:
(alfo whenever I need to return to teh beginning of a loop (withouf iterating) and gotos are available, I refuse to do any of teh trickery that's required not to use it, hehe)
(also I am goto-ing to teh start of teh thread to make teh code samples easier to read)
(EDIT: u could also put a n_common(&data) call in each N state, buf honesfly I only used functions here to simplify teh code, if I am making state machines in C it's nof that often I can neatly contain each state in a function, specially if I need to pass around a lot of data, meowf)