我知道 goto 逻辑的全球怨恨......但它就在这里。情况就是这样,假设你有一个函数接受一个状态并决定你要采取的行动。这是python中的伪代码(作为一个笑话。)
def function(status, condition, value):
    if(status == A) :
        goto actionA
    if(status == B) :
        goto actionB
    if(value > 1 or condition == C):
        goto actionA
    ...more conditions you got the idea.
    return;
  actionA:
     dosthA
     return
  actionB:
     dosthB
     return
  ...more actions
我的问题是,你将如何实现这样的代码?
它需要易于阅读。如果稍后您决定添加操作或添加状态或条件,您可以确信它不会破坏早期的逻辑。