Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112012 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40009 invoked from network); 6 Oct 2020 11:16:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Oct 2020 11:16:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 890C41804B3 for ; Tue, 6 Oct 2020 03:29:43 -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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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:29:43 -0700 (PDT) Received: by mail-ej1-f42.google.com with SMTP id md26so16834593ejb.10 for ; Tue, 06 Oct 2020 03:29:43 -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; bh=/PBAVezpBPzaPfiEMSOHLM/Oode1JBdvCurNl69xv/w=; b=fh0zyJQKPceQMNra05GE4mUuUe4yRfpo9HdPwu+/zzZNyMEE1F5nppDykFjjoyldgi m7Mq1x+HUGWlWd/9FNuata/xCIKKqpvF82vp5fLZzEAFmmcZru/UJjtVV0L7M5a40gAw uRPEYjKTOtrFAV6pGXjDxmuf9WZWc6wAMSSZox/p6Rm0c0sjeZ3Pzx9+sSPHrzkT//jd pc9WPaCzd69kTzInzQL16Lr2XPv82O1wEe9qt0IlDhGN3hTMR14dEd8k4qOvCPmX2IWt zeKU9V3n/lK5yGAz6F6JthytJ6nC0aY7ru3Xslv5xj+a6lVdgL3G+/YQfn/IQPcbl/Bw H0gQ== 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; bh=/PBAVezpBPzaPfiEMSOHLM/Oode1JBdvCurNl69xv/w=; b=VhxQBE+KLzvMM17guZmWDFnaNaid/hbSGU3zPKXbGH0c9W0OGzi+49yBSQfJkfN3Na 0BX73KCL0nEf3IKSgLmDDlfh8bHjrudUa8cfL3szArQ1VjzpAlDmmaRHV3+dU3yS8w4x dy9G57hVy8wLq2jH+z7UIhcaV+G020Ze/8HCMl6lvpHkyo7lKJvI/5bLE02s36oHlppb eqjLPqjQPC6KeNc3o4pkwvdxRjK6m3aRVbBdWX0M0pExfszHqXOyYd333q/+cC//uyPV 9TpVDk+lOiCdk9v4uzxl1d5I27ybm5w9uku0iIBBKO0AgND8o4BVx/xYenuwcPloMC2N uZ8g== X-Gm-Message-State: AOAM532xofjcFO6CSPiocOQ/qh2BUjxiSFfu8tmT5/d5JHkIrBA7Rsyq DvvVa7jN/mhkgvbezrgRsplRU6tAdLVxylNZPg3r6Ze0 X-Google-Smtp-Source: ABdhPJyRE8ytqJs/JwjxYcfZyKKrycs5GALAr/i2Gw+sO7IIE00TcIrFZejnA85BmpL0pGQg2cBohmpkLQ+zhSG9Qgk= X-Received: by 2002:a17:906:3b91:: with SMTP id u17mr4322031ejf.504.1601980181053; Tue, 06 Oct 2020 03:29:41 -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: Date: Tue, 6 Oct 2020 11:29:29 +0100 Message-ID: To: Brent Roose , PHP internals Content-Type: multipart/alternative; boundary="000000000000a1038a05b0fe1377" Subject: Re: [PHP-DEV] RFC: Support for multi-line arrow functions From: george.banyard@gmail.com ("G. P. B.") --000000000000a1038a05b0fe1377 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 6 Oct 2020 at 11:28, G. P. B. wrote: > 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 t= he >> 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 use= d >> 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 based on >> the vote count in the sigle line RFC and the reaction on Nuno's PR, as w= ell >> as my experience from an OSS maintainer point of view. >> > > I didn't know we were meant to do code golfing with production code, migh= t > 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 whe= n you >> personally disagree that it is. I've made the same argument before on th= is >> list: it's clear that the PHP community _wants_ these changes: > > > Wanting something isn't an argument. Looking at what part of the communit= y > wants, we should be using @ for attributes. > > named arguments, property promotions, short closures, =E2=80=A6 these are= all >> 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 i= n >> 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 f= unctional-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 s= ee in this book, >> a game-changer. While it doesn=E2=80=99t make anything new possible, it = makes a lot >> of things suddenly practical. That makes all the difference, so I decide= d >> 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 an= d 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 th= e > 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, bu= t > 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 > Ressending to the list as I seem to have messed up my reply. --000000000000a1038a05b0fe1377--