Hi SO-lers,
when writing small functions I often have the case that some parameters are given to a function which itself only passes them to different small functions to serve its purpose.
For example (C#-ish Syntax):
public void FunctionA(object param)
{
DoA(param);
DoB(param);
DoC(param);
// etc.
}
private void DoA(object param)
{
DoD(param);
}
private void DoD(object param)
{
// Error if param == null
param.DoX();
}
So the parameters are not used inside the called function but "somewhere" in the depths of the small functions that do the job.
So when is it best to check if my param-Object is null?
When checking in FunctionA:
Pro: -There is no overhead through the use of further methods which at last will do nothing because object is null.
Con: -My syntactically wonderful FunctionA is dirtied by ugly validation code.
When checking only when param-object is used:
Pro: -My syntactically wonderful FunctionA keeps a joy to read :)
Cons: -There will be overhead through calling methods which will do nothing because the param-object is null. -Further cons I don't think about at the moment.