Could all Code ever written be improved by applying the State Machine Pattern?
I was working on a project that was a mass of horrendous awful, buggy, broken spaghett
Finite state machines (FSM's) and more specifically domain specific languages (DSL's) make it easier to match a problem to one specific solution domain, by describing the solution in a specialised language.
The limitations of the State Machine pattern is that it itself constitutes a programming language, but one for which you have to write your own execution, testing and debugging tools; and one which any maintainer has to learn. You have moved the complexity of your code into a complex FSM configuration. Occasionally, this is useful, but certainly not universally.
And since any von Neumann computer is itself a FSM, then certainly any program can be recast in this fashion.