On 2012-07-21 10:28, Stas Malyshev wrote:
Hi!
If I understand this correctly, this is like what Python let's you do
with tuples. It's handy for getting vector components, hostnames and
port numbers, etc. (I apologise for the Python comparison, it is just
the language where I usually encounter this, and it makes heavy use of
foreach-style loops and tuples)
There's no need to apologize for Python comparison, Python is not a
dirty word :) However, in PHP functions rarely return sets of tuples
that can be manageably unpacked by this foreach syntax - usually it's
either something like DB result set, which has unpredictable number of
values, or one set of values, which doesn't need foreach. That's why I
wanted to see a use case where this is beneficial.
The number of values in a DB result set may be unpredictable, but the
number of _elements_ in each value shouldn't be - and the list() will be
on those elements:
foreach($resultset as list($id, $name, $address, $phone))
{
....
}
(Assuming I don't use array_map instead - $resultset might not be an array.)
Incidentally this also touches on something you say later:
On 2012-07-21 11:03, Stas Malyshev wrote:
>
> IMHO assignment is always more readable than function with magic
> unobvious effects. I'd rather always have assignments than scratch my
> head each time reading the code - is this the one that modifies the
> argument or the one that doesn't?
>
I agree fully with this; having functions actually behaving like, well,
_functions_ makes it much easier to see what's going on (I don't have to
look up the definition of foo($bar) to see whether it's modifying $bar
or not).
So when I have a function that has a two- or multi-part result then -
instead of having one part as the return value and the others by
reference - in Python I'd return a tuple.
I like what has been done to improve support for functional programming
(despite the elephant in the room); I guess that's why I'm cold to the
other proposal to graft OO syntax onto non-OO semantics.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php