I agree. If you need to nest if-thens more than 4 deep then a switch-case is better.
Well, I'm not sure that switches are superior in that context. A switch statement might directly replace
if ( state == 1 ) {
} else if (state == 2 ) {
} else if (state == 3 ) {
} //etc
but I don't regard that as being nested in the destructive ways that I have seen.
I was thinking more of
if ( state == ) {
if ( inputA == ) {
if (inputB == && inputC == ) {
if (inputD == ) {
if (inputE == ) {
}
}
if (inputE == ) {
}
}
} else if (state == ) {
}
plus other peversions carried out to the 10th level!
Yes, I refused to look at it in detail, let alone consider modifying it. There was zero chance of spotting the line that needed to be modified to implement one use-case,
while ensuring that it didn't affect other use-cases.
No, it wasn't remotely sensible, but that's the kind of
thing that accretes over the years. Cancerous.
Any design pattern can be implemented badly, but at the GoF Class-per-State Pattern can neatly and directly implemented FSMs with nested states.
(Shortform features including: one abstract superstate for operation, another abstract superstate for faults, and concrete substates within a superstate for the normal operation FSM, catch all error events occurring in any substate causing a transition to the fault state, etc)