Which is the best way of validating an input passed to the function i.e. do you validate all input before proceeding some thing like
class A;
void fun(A* p)
{
if(! p)
{
return;
}
B* pB = p->getB();
if(! pB)
{
return;
}
.......
}
Or do you write it like this:
void fun(A* p)
{
if(p)
{
B* pB = p->getB();
if(pB)
{
.....
}
}
}
I am asking this because, if I use the first style then I'll have multiple return statements in my code which many people say are bad (don't know why) and if I use the second style then there will be too many levels of nesting in my code.