Michael Feathers illustrates nicely the problem of overcautious coding. The following should probably be coding principles:
Spurious null checks are a symptom of bad code.
The reactive thing whenever there is a core dump or crash because of
nulls or empty pointers is to add a check of
null and wash your hands off it. The right thing would be to find out origin of the
null and try to avoid it as much as possible. It is not only that the
if-endif can cause performance loss, it can inadvertently cover up the malicious code that generates the null.
It is also easier to program to an interface where the callee does not throw nulls so that the multiple callers don’t have to check for them.
Copyright Abhijit Nadgouda.