How much null checking is enough?

后端 未结 18 1146
清酒与你
清酒与你 2021-01-30 01:10

What are some guidelines for when it is not necessary to check for a null?

A lot of the inherited code I\'ve been working on as of late has null-checks

18条回答
  •  耶瑟儿~
    2021-01-30 01:38

    Lower level code should check use from higher level code. Usually this means checking arguments, but it can mean checking return values from upcalls. Upcall arguments need not be checked.

    The aim is to catch bugs in immediate and obvious ways, as well as documenting the contract in code that does not lie.

提交回复
热议问题