101 reputation
1
bio website
location
age
visits member for 2 years, 11 months
seen Dec 6 '13 at 8:29

Dec
6
comment Should we always write Defensive null check in code?
I agree with @CodeCaster - it depends. I see a lot of "defensive" code that does "if (fred != null) { fred.doSomethingVital());}" but does not take any action if fred IS null. All this is defending against is a null reference - it doesn't defend the application at all if the call to fred.doSomethingVital() is actually key to the business operation the application is supporting. In this case it would probably be safer to not check the null reference - at least the code will fail quickly and noisily.