[RFC] Square bracket syntax for array destructuring assignment

php.internals

Andrew Faulds

10 years ago
Hi everyone, Bob and I have made an RFC which proposes an alternative syntax for list(): https://wiki.php.net/rfc/short_list_syntax Please tell us your thoughts. Thanks!
-- Andrea Faulds https://ajf.me/

Midori Kocak

10 years ago
+1

Lester Caine

10 years ago
DO WE HAVE TO PUT UP WITH THIS STUPIDITY? Top posting 2 characters AND including all the sig .... On 07/04/16 13:29, Midori Kocak wrote:
> +1 > >> On 07 Apr 2016, at 14:21, Andrea Faulds <ajf@ajf.me> wrote: >> >> Hi everyone, >> >> Bob and I have made an RFC which proposes an alternative syntax for list(): >> >> https://wiki.php.net/rfc/short_list_syntax >> >> Please tell us your thoughts. >> >> Thanks! >> -- >> Andrea Faulds >> https://ajf.me/ >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> > >
Do we really need to make everything so shorthand that one has no idea what one is looking at when scanning code?
-- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

Marco Pivetta

10 years ago
Yes, Lester :-P Also, +1 to the RFC. On Apr 7, 2016 14:37, "Lester Caine" <lester@lsces.co.uk> wrote:

Rowan Collins

10 years ago
Lester Caine wrote on 07/04/2016 13:37:
> DO WE HAVE TO PUT UP WITH THIS STUPIDITY? > Top posting 2 characters AND including all the sig ....
Hi Lester, If you want to remind people of the mailing list rules, the link you are looking for is http://git.php.net/?p=php-src.git;a=blob_plain;f=README.MAILINGLIST_RULES;hb=HEAD While you're there, you might want to note that "respect other people" and "do not post when you are angry" are both classed as "rules", as is "keep message signatures to a maximum of 2 lines if at all necessary", whereas "do not top post" is classed as a "hint". Regards,
-- Rowan Collins [IMSoP]

Stephen Coakley

10 years ago
On 04/07/2016 07:37 AM, Lester Caine wrote:
> > Do we really need to make everything so shorthand that one has no idea > what one is looking at when scanning code? >
That's the goal right? We're trying to make Perl 7 here. Just kidding. I like it because it makes the syntax look consistent with the already available short array syntax.
-- Stephen

Paul M Jones

10 years ago
> On Apr 7, 2016, at 07:21, Andrea Faulds <ajf@ajf.me> wrote: > > Hi everyone, > > Bob and I have made an RFC which proposes an alternative syntax for list(): > > https://wiki.php.net/rfc/short_list_syntax > > Please tell us your thoughts.
Reading the name of the RFC led me to imagine what I thought it might be, and lo, it was! So, yes, I like it.
-- Paul M. Jones http://paul-m-jones.com

Bishop Bettini

10 years ago
On Thu, Apr 7, 2016 at 8:21 AM, Andrea Faulds <ajf@ajf.me> wrote:
> Hi everyone, > > Bob and I have made an RFC which proposes an alternative syntax for list(): > > https://wiki.php.net/rfc/short_list_syntax > > Please tell us your thoughts. >
Thanks for your (plural) work on this RFC. You have my vote. I especially appreciate the symmetry.

Fleshgrinder

10 years ago
+1 love it :)
-- Richard "Fleshgrinder" Fussenegger

Markus Fischer

10 years ago
Hey, On 07.04.2016 14:21, Andrea Faulds wrote:
> Bob and I have made an RFC which proposes an alternative syntax for list(): > > https://wiki.php.net/rfc/short_list_syntax > > Please tell us your thoughts.
Reading the last sample in the RFC:
> Both due to implementation issues, and for consistency's sake, list()
cannot be nested inside [], nor vice-versa: [...]
> // This, however, is allowed: > [[$a, $b], [$c, $d]] = [[1, 2], [3, 4]];
and then
> This RFC has no impact upon OPcache or other extensions dealing with
PHP opcodes, because the compiled result is identical to the list() syntax. Without any deeper technical knowledge, these two things don't look compatible to me at first. It's probably a non-issue, but mentioning the list() can't be nested, the new destructuring syntax can, but "the compiled result is identical to the list() syntax" doesn't add up somehow. If you can elaborate on this, that wold be nice. Thanks :) - Markus

Björn Larsson

10 years ago
Den 2016-04-07 kl. 21:11, skrev Markus Fischer:
> Hey, > > On 07.04.2016 14:21, Andrea Faulds wrote: >> Bob and I have made an RFC which proposes an alternative syntax for list(): >> >> https://wiki.php.net/rfc/short_list_syntax >> >> Please tell us your thoughts. > Reading the last sample in the RFC: > >> Both due to implementation issues, and for consistency's sake, list() > cannot be nested inside [], nor vice-versa: > [...] >> // This, however, is allowed: >> [[$a, $b], [$c, $d]] = [[1, 2], [3, 4]];
I read it as it's the combination that is not allowed, but nesting list itself works. So adding following to RFC might be enough: "... // This, however, is allowed: [[$a, $b], [$c, $d]] = [[1, 2], [3, 4]]; // In a similar fashion like list(list($a, $b), list($c, $d)) = [[1, 2], [3, 4]];" Anyway, nice and well written RFC, +1! Regards //Björn

Cameron Ball

10 years ago
This gets a vote from me. The symmetry is very nice :]

Ivan Enderlin @ Hoa

10 years ago
Hello, On 07/04/16 14:21, Andrea Faulds wrote:
> Hi everyone, > > Bob and I have made an RFC which proposes an alternative syntax for > list(): > > https://wiki.php.net/rfc/short_list_syntax > > Please tell us your thoughts. > > Thanks!
Thanks a lot for this RFC. Huge +1 from the all Hoa's community and myself. However, did you discuss about `[…]` vs. `{…}`? Most of the time, arrays or vectors constructing are represented by `[…]` symbols while destructing are represented by `{…}`. What your point of view or arguments here? Again, thanks!

Rowan Collins

10 years ago
On 08/04/2016 08:43, Ivan Enderlin wrote:
> Most of the time, arrays or vectors constructing are represented by > `[…]` symbols while destructing are represented by `{…}`. What your > point of view or arguments here?
When you say "most of the time", do you mean in other languages? Which other languages? Importantly, do those other languages have similar semantics to PHP? I'm reminded me of the suggestion that PHP short array syntax should look more like JSON, which to me would be a terrible idea, because PHP arrays have very different behaviour from JavaScript objects, on which JSON is modelled. Regards,
-- Rowan Collins [IMSoP]

Ivan Enderlin @ Hoa

10 years ago
On 08/04/16 12:17, Rowan Collins wrote:
> On 08/04/2016 08:43, Ivan Enderlin wrote: >> Most of the time, arrays or vectors constructing are represented by >> `[…]` symbols while destructing are represented by `{…}`. What your >> point of view or arguments here? > > When you say "most of the time", do you mean in other languages?
Yes.
> Which other languages?
Javascript, Rust, Python… I don't know the exact syntax but I see this kind of syntax often. Actually, both exist. I am just curious and wonder if you think about using another syntax, and if yes, why choosing this one.
> Importantly, do those other languages have similar semantics to PHP? > I'm reminded me of the suggestion that PHP short array syntax should > look more like JSON, which to me would be a terrible idea, because PHP > arrays have very different behaviour from JavaScript objects, on which > JSON is modelled.
Totally agree. Regards.

Andrew Faulds

10 years ago
Hi Ivan, Ivan Enderlin wrote:
> Thanks a lot for this RFC. Huge +1 from the all Hoa's community and myself. > However, did you discuss about `[…]` vs. `{…}`? Most of the time, arrays > or vectors constructing are represented by `[…]` symbols while > destructing are represented by `{…}`. What your point of view or > arguments here?
I'm not sure I understand what you mean. In JS, for example, you use {} to create an object or for destructuring assignment for an object. But you don't use {} for other cases. [] is used to create arrays and for destructuring assignment from arrays. The pattern resembles the syntax for constructing what it matches against. In Haskell, (…,…) is used for constructing a tuple and pattern-matching against it. I can't think of a language where {…} is used for destructuring or pattern-matching against something which is not written with {…}. Does that make sense?
-- Andrea Faulds https://ajf.me/

Ivan Enderlin @ Hoa

10 years ago
Hi Andrea, On 08/04/16 13:26, Andrea Faulds wrote:
> Hi Ivan, > > Ivan Enderlin wrote: >> Thanks a lot for this RFC. Huge +1 from the all Hoa's community and >> myself. >> However, did you discuss about `[…]` vs. `{…}`? Most of the time, arrays >> or vectors constructing are represented by `[…]` symbols while >> destructing are represented by `{…}`. What your point of view or >> arguments here? > > I'm not sure I understand what you mean. In JS, for example, you use > {} to create an object or for destructuring assignment for an object. > But you don't use {} for other cases. [] is used to create arrays and > for destructuring assignment from arrays. The pattern resembles the > syntax for constructing what it matches against. In Haskell, (…,…) is > used for constructing a tuple and pattern-matching against it. > > I can't think of a language where {…} is used for destructuring or > pattern-matching against something which is not written with {…}. > > Does that make sense?
Yup.

Alex Sky

10 years ago
Maybe in the future when there will be an inline object {}, you will need to make the destructuring {}

Sebastian Bergmann

10 years ago
Am 07.04.2016 um 14:21 schrieb Andrea Faulds:
> Please tell us your thoughts.
+1

Stephen Coakley

10 years ago
On 04/07/2016 07:21 AM, Andrea Faulds wrote:
> Hi everyone, > > Bob and I have made an RFC which proposes an alternative syntax for list(): > > https://wiki.php.net/rfc/short_list_syntax > > Please tell us your thoughts. > > Thanks!
Mhm, yes, I like it a lot! +1
-- Stephen