Hey everyone. I've been contemplating something lately and I haven't been able to come to a conclusion, so I thought I'd see what you all thought about it.
When checking for null (nevermind that we should try to not make something null in the first place), would it be better to check that something is not null and continue, or to check if it is null and exit the method early? ie:
A)
void method()
{
if(object != null)
{
dostuff;
}
}
or:
2)
void method()
{
if(object == null)
return;
dostuff;
}
I tend to like option 2 better because it removes a level of indentation and it's just nicer to look at. On the other hand, I think remember hearing someplace that returning in the middle of a method is bad for some reason. I don't remember why, just that it is. So, if anyone has any ideas/thoughts/input I'd like to hear them!