Finite State Machine Pattern - The One True Pattern?

后端 未结 2 404
南方客
南方客 2020-12-24 07:47

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

2条回答
  •  天涯浪人
    2020-12-24 08:31

    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.

提交回复
热议问题