Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to check for null, in calling method or in function? [duplicate]

Tags:

null

Should a check for null occur before making the call to a function or within the function itself?

like image 669
zsharp Avatar asked Jan 24 '23 17:01

zsharp


1 Answers

I would say within the call itself. That way, you only check for null in one place, not 5 places if you call that function from 5 different spots.

But this isn't a for sure answer. It really depends on the function and what the consequences are of calling it with a null argument.

like image 133
ryeguy Avatar answered Jan 26 '23 07:01

ryeguy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!