Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112011 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38670 invoked from network); 6 Oct 2020 11:15:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Oct 2020 11:15:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 101D01804B3 for ; Tue, 6 Oct 2020 03:28:26 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 6 Oct 2020 03:28:25 -0700 (PDT) Received: by mail-ed1-f53.google.com with SMTP id b12so12939882edz.11 for ; Tue, 06 Oct 2020 03:28:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FBQi/KY5zy5nMXgI3Q49EIjGVVgpC71PHZt8xmiC+Cs=; b=i/1kwzJJoQXhj2gLYN8j+MJFb82xDlpkPmAzyH6aqwLmsIFuziuOQuCMUCDzSuS+VF qYTOyoYku5ezyjj/u/KH/1fqACdZMWu2Rq+PjhN0HvWh7uMOaRbaVUoarXWY5pT3SGFK t2MglPSGWrtYwXtlE7gspYIh22o6fvDUTJcD+SKqsRJTKKZmvH9xJnIJKO3tajps1AZI TQxGGbv71DdKRgQbhfzfS4LdXylWaaVgwmDAAo/Fz7xl/VKIPN53lbXoVppWGG2bzvfh rtrgwG9RNN9avSYJ45ULRSweCJy26MdP69ksk1EUy2Jn6lm+FFzYIF9SnF/wpQukUU4g /xGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FBQi/KY5zy5nMXgI3Q49EIjGVVgpC71PHZt8xmiC+Cs=; b=PoVwJBvsIAztHfLSrn82Kc3EzN/bu7K5LalsUY+ABZaGL0ino/a76KlWsjSK+P9LBD gjHio+EkuI129NBGn2Xrm0jzu+p+xFZ6GBxad73XVe+bh7AKU9GzteMvn4Wq/ARijnNz PJzyar+fQPhX/xnbQLYusawfM3ak1YYJkJkrvlMhG8Y5GeIy6NPCQzE8CRQYkGLla7Dz R9H5Be4IBt7ot4nuRitcrtDH3GMzg+q+HcozvEG5DwlwPzyj4rx1evd4Idu22voI/R0y iXLE1NmQ5rprW0WffSi26Tdan5g63OszusbOeaMEjaVNb73GuZDPCQACyQbGKvkeFHoc XifQ== X-Gm-Message-State: AOAM532FdpY5IM+CHDtAMGlAI3bNsEpJOxb0BcQSY7zNSeTkg6wcMSRY +8nI7TlUoOCCPtju6Pb2uWj1TNd1wBnSmZNyFQseC+K60Ws= X-Google-Smtp-Source: ABdhPJx0alaDS0TjenBYXiOzPBeNbkrPYpfH448em8zPhESUqt9mWI+qBccrUtEEPm3FlNv4xwvx9ONBOoNGHm7p6f0= X-Received: by 2002:aa7:ccc8:: with SMTP id y8mr4706105edt.325.1601980101716; Tue, 06 Oct 2020 03:28:21 -0700 (PDT) MIME-Version: 1.0 References: <446c9894-191f-e53b-4534-31c4e7b91d7b@gmail.com> <881e2335-5f81-0d79-6a17-06bc20f14223@gmx.net> <873361ff-02c8-b9df-9b7a-c9e89e25a880@gmx.net> <7F014A40-2D47-4DA6-8A38-59518218F9CA@stitcher.io> In-Reply-To: <7F014A40-2D47-4DA6-8A38-59518218F9CA@stitcher.io> Date: Tue, 6 Oct 2020 11:28:10 +0100 Message-ID: To: Brent Roose Cc: Levi Morrison via internals Content-Type: multipart/alternative; boundary="000000000000e66d9b05b0fe0eb8" Subject: Re: [PHP-DEV] RFC: Support for multi-line arrow functions From: george.banyard@gmail.com ("G. P. B.") --000000000000e66d9b05b0fe0eb8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable First, can you please bottom-post and not top-post. On Tue, 6 Oct 2020 at 09:53, Brent Roose wrote: > Hi internals > > The reason multi-line short closures are so valued by userland devs is > because they are shorter to write and prettier to read. While some of us > might not agree on the definition of "prettier to read", it was one of th= e > key arguments for adding short closures in the first place: > > > Anonymous functions in PHP can be quite verbose, even when they only > perform a simple operation. Partly this is due to a large amount of > syntactic boilerplate, and partly due to the need to manually import used > variables. This makes code using simple closures hard to read and > understand. This RFC proposes a more concise syntax for this pattern. [1] > > > > We can have the discussion again on whether we like short closures or not= , > but it turned out most of internals _and_ userland devs do =E2=80=94 base= d on the > vote count in the sigle line RFC and the reaction on Nuno's PR, as well a= s > my experience from an OSS maintainer point of view. > I didn't know we were meant to do code golfing with production code, might have missed a memo somewhere. > Furthermore, the `use(*)` syntax misses the point of this proposal: it's > not about being able to use all variables from the outer scope, If it's not about being able to use all variables (or even just one that is irrelevant) from the outer scope, then what is the point? Saving 6 characters by only writing fn() {} instead of function {}? > it's about a clean syntax that's as short as possible =E2=80=94 even when= you > personally disagree that it is. I've made the same argument before on thi= s > list: it's clear that the PHP community _wants_ these changes: Wanting something isn't an argument. Looking at what part of the community wants, we should be using @ for attributes. named arguments, property promotions, short closures, =E2=80=A6 these are a= ll > features that aren't _necessary_, still they are great features of a > modern-day language. > Obviously nothing is necessary, we could write assembler style with only goto statements. I also want to quote from Larry Garfields book on thinking functionally in > PHP [2], to demonstrate the signicant impact short closures already had > today: > > > =E2=80=9CCombined with PHP=E2=80=99s overall clunky syntax for doing fu= nctional-esque > code, I generally didn=E2=80=99t go further than =E2=80=9Cpure functions = are your friend,=E2=80=9D > either in my own code or what I explained to others. > > > > That is, until PHP 7.4. > > > > PHP 7.4=E2=80=99s introduction of short lambdas is, as we=E2=80=99ll se= e in this book, a > game-changer. While it doesn=E2=80=99t make anything new possible, it mak= es a lot > of things suddenly practical. That makes all the difference, so I decided > it was time to buckle down and really dig into functional programming.=E2= =80=9D > > Larry continues to write a whole book about functional programming in PHP= , > and short closures play a significant role. > Finally a resemblance of an actual argument. > So I hope to see more input on Nuno's PR from a techinical point of view: > what's missing, what's needed to get this to the RFC phase, =E2=80=A6 and= not only > discussions about what syntax we like or not, or whether there are other > ways to solve the same problem. Please provide Nuno with actionable > feedback. > > Kind regards > Brent > > [1] https://wiki.php.net/rfc/arrow_functions_v2 < > https://wiki.php.net/rfc/arrow_functions_v2> > [2] https://leanpub.com/thinking-functionally-in-php < > https://leanpub.com/thinking-functionally-in-php> > Jokes aside, the actionable feedback is to argue *why* auto capture of the outer scope should be added to the language as "it is very not PHP" a direct quote from Rasmus from his talk "25 years of PHP" [1] and from the same section one of the reasons why people don't mind the current single line expression form is because it doesn't look like a new scope. As Rowan said in his analysis changing this specific behaviour of scope being able to "leak" into another one needs a lot of justification, the current short closure syntax doesn't even use braces {} which are the de facto signal in PHP that you are entering in a new scope. Going back to the `use(*)` syntax: the reason why people propose this extension (which is not mutually exclusive with adding support for fn {} without outer scope capture, albeit strange) is that it is more in PHP traditional design philosophy. You can argue against this syntax and in favour of Nuno's, but again it is NOT missing the point. Moreover, Larry has also made a PR which extends short closures [2] in a way I personally find way more appealing. Regards George P. Banyard [1] https://youtu.be/Qa_xVjTiOUw?t=3D1895 [2] https://github.com/php/php-src/pull/6221 --000000000000e66d9b05b0fe0eb8--