Is there an alternative to hyper-indented code?

后端 未结 7 488
甜味超标
甜味超标 2020-12-16 22:36

I often run into code that has to perform lots of checks and ends up being indented at least five or six levels before really doing anything. I am wondering what alternativ

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 22:51

    See Flattening Arrow Code for help.

    1. Replace conditions with guard clauses.
    2. Decompose conditional blocks into seperate functions.
    3. Convert negative checks into positive checks.

提交回复
热议问题