What is the best way to replace or substitute if..else if..else trees in programs?

后端 未结 21 1125
迷失自我
迷失自我 2020-11-28 06:23

This question is motivated by something I\'ve lately started to see a bit too often, the if..else if..else structure. While it\'s simple and has its uses, somet

21条回答
  •  粉色の甜心
    2020-11-28 07:01

    I would go so far as to say that no program should ever use else. If you do you are asking for trouble. You should never assume if it's not an X it must be a Y. Your tests should test for each individually and fail following such tests.

提交回复
热议问题