What is the benefit of terminating if … else if constructs with an else clause?

前端 未结 12 1070
不思量自难忘°
不思量自难忘° 2020-11-27 13:37

Our organization has a required coding rule (without any explanation) that:

if … else if constructs should be terminated with an el

12条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 14:16

    This, is done to make the code more readable, for later references and to make it clear, to a later reviewer, that the remaining cases handled by the last else, are do nothing cases, so that they are not overlooked somehow at first sight.

    This is a good programming practice, which makes code reusable and extend-able.

提交回复
热议问题