Reputation
Next privilege 125 Rep.
Vote down
Badges
1
Newest
 Supporter
Impact
0 people reached

  • 0 posts edited
  • 0 helpful flags
  • 2 votes cast
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.
May
4
awarded  Supporter