Re: RE: Return or not to return, that is the question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



----- 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux