How to prevent the arrowhead anti-pattern

后端 未结 13 1320
南旧
南旧 2020-12-05 06:37

I\'m a bit confused about how to best refactor my code into something more readable.

Consider this piece of code:

var foo = getfoo();
if(foo!=null)
{         


        
13条回答
  •  一向
    一向 (楼主)
    2020-12-05 06:48

    If you can change the stuff you are calling, you can change it to never ever return null, but a NULL-Object instead.

    This would allow you to lose all the ifs completely.

提交回复
热议问题