Hello list,

I'd like to share a brief critique of the proposed "foreachlist" feature -

https://wiki.php.net/rfc/foreachlist

The argument that this makes code more flexible, is questionable - in my
opinion, it makes the code less flexible, since nested arrays have to be
nested with their dimensions in the order you expect to iterate through
them. This makes refactoring more difficult, since if you want to change the
iteration order, you'll need to either reorganize the dimensions of the
array, or fall back on the old syntax, using two nested foreach statements.

In my opinion, this syntax gives you less control, in favor of shorter
syntax - and all you've saved is a couple of curly braces and the word
"foreach", which just got replaced with the word "list" anyway. So I don't
even see how this is very convenient.

I also don't think this syntax is very transparent - it's not by any means
obvious what's happening, and this syntax is going to throw off newcomers.
It makes it appear as though you're performing one loop iteration, when
you're actually performing two (or more) nested iterations.

And finally, it's not clear to me how this feature would work in conjunction
with the "break" and "continue" statements - at what dimension would a break
or continue statement operate? the inner-most? or the outer-most? Either
way, this is not going to be obvious from reading the code.

Or would the break/continue statements not work at all? In that case, I
would argue again that this feature complicates refactoring, and also in
some cases optimization, since you would have to rewrite the code using
nested foreach-statements to eliminate redundant processing by using break
or continue.

In my opinion, this feature is syntactic sugar - I find it unnecessary, and
it does not add any considerable benefits in terms of code volume or
clarity. It harms transparency, ease of refactoring and potentially
performance, too.

I don't see a description in the RFC explaining what this feature is for, or
how it compares to existing syntax?

And even so, it would be a hard sell for me.

Regards,
   Rasmus Schultz

Reply via email to