Re: RE: Return or not to return, that is the question
| From: | Richard Davey | Date: | Wed, 30 May 2007 16:24:08 +0000 |
| Subject: | Re: RE: Return or not to return, that is the question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-255819@lists.php.net to get a copy of this message | ||
Hi Jared,
Wednesday, May 30, 2007, 4:10:45 PM, you wrote:
[snip]
> I think putting "return;" at the end of every function is probably a healthy
> practice, but is it best practice? If it's poorly written and/or poorly
> factored code, it doesn't make any difference if they have returns on
> everything, it's still junky code.
If you do put a return; at the end of all of your functions, I'm
curious as to why? If a function doesn't actually return a value
(which is highly possible) then it isn't /required/, but that doesn't
stop me from doing it. I *do* put 'return;' at the end of all
functions (my question to the list was - does anyone else?)
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'.
Based on the variety of replies it appears there is no 'standard' for
this. Just as with code structure and studly-caps it's obviously a bit
of a religious debate.
I think perhaps it is a psychological thing actually, as if I don't
consider the function 'finished' until it hits a return;. Almost like
you're issuing an instruction to tell PHP "yes, as the programmer I am
now happy for you to return to where-ever you were called from" -
perhaps just a way of exerting our control :)
> Should those checks be contained in the codeblock or class BEFORE returning?
> I think so.
I would agree (because it's how I do it ;), but this isn't an approach
everyone takes.
Cheers,
Rich
--
Zend Certified Engineer
http://www.corephp.co.uk
"Never trust a computer you can't throw out of a window"