Should a function return null?
E.g.
function test()
{
return null; // vs return;
}
Is the latter considered bad practice or doesn’t it matter?
PS
Whether it is bad practice shouldn’t be subjective IMHO.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you don’t return anything, just use
return;or omit it at all at the end of the function.If your function is usually returns something but doesn’t for some reason,
return null;is the way to go.That’s similar to how you do it e.g. in C: If your function doesn’t return things, it’s
void, otherwise it often return either a valid pointer or NULL.