How much null checking is enough?

后端 未结 18 978
清酒与你
清酒与你 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:28

    It's widely known that there are procedure-oriented people (focus on doing things the right way) and results-oriented people (get the right answer). Most of us lie somewhere in the middle. Looks like you've found an outlier for procedure-oriented. These people would say "anything's possible unless you understand things perfectly; so prepare for anything." For them, what you see is done properly. For them if you change it, they'll worry because the ducks aren't all lined up.

    When working on someone else's code, I try to make sure I know two things.
    1. What the programmer intended
    2. Why they wrote the code the way they did

    For following up on Type A programmers, maybe this helps.

    So "How much is enough" ends up being a social question as much as a technical question - there's no agreed-upon way to measure it.

    (It drives me nuts too.)

提交回复
热议问题