NYCPHP Meetup

NYPHP.org

[nycphp-talk] Question about explicit returns

Tod Dailey christiandailey at gmail.com
Fri Jan 11 13:23:15 EST 2008


That's part of the reason I'm asking here, as the replies I've received
weren't that informative. I've heard that method #1 is a left-over practice
from C/Java programmers, and isn't necessary with PHP (??). I've also heard
the argument that returning inline values is faster, and easier to see
exactly what is being returned. That pretty much sums up what I've heard
so-far.

Christian


On Jan 11, 2008 1:02 PM, David Krings <ramons at gmx.net> wrote:

> Tod Dailey wrote:
> > The validity of one of my coding practices that I've used for awhile has
> > recently come under question. I've tried to listen to arguments on both
> > sides, and there seems to be good points on both ends, but my question
> > still hasn't been answered to my satisfaction.
>
> I use version 1 (can it be that you forgot to return $result at the end?)
> where I declare anything that is used in the function at the top,
> including
> booleans. I then do whatever I want/need to do in that function and set
> the
> flag accordingly and then return the result at the very end of the
> function
>  I see the benefits of the second version as there is a direct return of
> the
> state and it saves a variable. Without having it tried out any other way,
> I
> find version 1 to be easier to debug. In v1 you can evaluate $result
> before
> retruning it, can't do that with v2. V2 is potentially faster as it
> doesn't
> have to go through who knows how many lines of code first before it
> reaches
> the return at the end. As soon as a return is hit in the function the
> function
> exits and sends back the return values.
>
> I'd develop using v1 and then see later if optimizing using v2 makes
> sense. It
> would be interesting to know the pros and cons for either version that you
> have heard so far.
>
> David
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20080111/80fff8f9/attachment.html>


More information about the talk mailing list