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

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

 



On Wed, May 30, 2007 7:56 am, Jay Blanchard wrote:
> Classically this would need a return, because $this->counter is going
> to
> be less than 100 most of the time, and you may want to return the
> value
> at some point.

Or you may not ever need to return it.

And if you return it for no reason, you have to document what the
function returns, maintain it as returning that, and can never decide
to return something else more useful tomorrow, when you find out what
you actually need to return.

> Here is the thing (it is akin to all of the holy wars on brackets,
> etc),
> the use of return has been pounded into old-schoolers heads for a long
> time, regardless of the Boolean or value returned. It is good style
> and
> it introduces consistency. As far as it being an extra line of code?
> So
> be it! We're not in the day and age where we had to count CPU cycles!
> If
> anyone is designing PHP applications with that level of granularity
> they
> have entered into an amazingly pedantic process for which PHP is not
> well suited.

As I recall, the reasons for always returning something in C are
pretty irrelevant to PHP...

I think there was a time when (void) was not a valid return data type,
so you HAD to return at least an (int) -- and programmers would start
to rely on the essentially random value being returned always being 0
when it wasn't going to always be 0 -- it just happened to always be 0
due to that was what was always in the byte on the stack... Until you
changed your code and the whole thing went to the toilet because of
the assumption about what was being returned.

PHP and C have many similarities, but that doesn't mean that every
Best Practice is going to transfer over, because they are very very
different languages.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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