----- Original Message -----
From: "Richard Davey" <rich@xxxxxxxxxxxxx>
That is all my original thread was ever really asking - I was just
curious what other people thought about returning from functions that
don't actually require a return value. So far the responses have been
pretty varied, from the (somewhat blinkered) 'how can a function never
return something?', to 'yes I always return' to 'no I just let it run
out'.
My rule is to write what you mean, and if you don't mean to return anything
valid or worth anything, just don't. If you explicitly put a return it
should be for a reason, whatever you return should be meaningful. If I find
a 'return true' at the end of a piece of code, I will check if there is any
condition where it returns false, because I will assume that the return true
is significant and so should be its obvious alternative. I would also
wonder why the caller doesn't use that return value or if it does, why is
there no 'else' part.
In a similar line, I use 'null' in databases when I mean 'I have no valid
information for this field'. Basically, the idea is to be clear in what you
mean. If you put a return it should be because you mean to return
something. If you mean you don't know, use 'null', don't default to zero or
any other implausible value for that field. This kind of arbitrary
conventions dilute the self-documenting value of well-written code, quite
the opposite, they would need to be documented themselves to avoid
missinterpretations.
Satyam
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php