I personally would disagree with you on that one. I think the single
return point is more confusing. Though that is more of a preference.
The single return path leads to extra processing that would not be required.
On Mar 15, 2013 9:12 PM, "Robert Stoll" wrote:
> I would say the first version
I would say the first version is ok but only because your function is small
enough.
If your function gets bigger and bigger, then it is better to have only one
exit point in terms of readability.
Von: talk-boun...@lists.nyphp.org [mailto:talk-boun...@lists.nyphp.org] Im
Auftrag von Joseph Cra
The only reason would be poorly designed code where the return value could
change based on multiple separate conditionals. I have seen it in some
legacy code.
On Mar 15, 2013 5:50 PM, "Anthony Ferrara" wrote:
>
> The first is fine. There's no reason not to do it...
>
>
> On Fri, Mar 15, 2013 at
The first is fine. There's no reason not to do it...
On Fri, Mar 15, 2013 at 5:30 PM, Joseph Crawford wrote:
> There are a few things to learn from here.
>
> First it is not only a styling thing. In the first one you have several
> return
> statements and in the second you only have 1 return s
There are a few things to learn from here.
First it is not only a styling thing. In the first one you have several return
statements and in the second you only have 1 return statement.
It will depend on the code logic but I tend to return when I have the value I
need rather
than assign it to a
function whatever(Array $array) {
foreach ($array as $key => $value) {
if ($something) {
return true;
}
}
return false;
}
Is there any reason -- style, legibility, whatever -- not to do the above?
Or should you do something like
function whatever(Array