Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112010 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32275 invoked from network); 6 Oct 2020 09:39:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Oct 2020 09:39:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DDFC61804D9 for ; Tue, 6 Oct 2020 01:53:13 -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,HTML_MESSAGE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from srv015.mail.ichtushosting.com (srv015.mail.ichtushosting.com [159.69.182.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 6 Oct 2020 01:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=stitcher.io ; s=default; h=Message-Id:In-Reply-To:To:References:Date:Subject:Mime-Version :Content-Type:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=ZP9bxXn+65sm6c6xbX1Qaqsyuiho9U6Wk8Yi5qcdy9o=; b=trBZJ97UiyO+9JHStiKEXpb5kQ FwJow3CQnK7BAv9d5hMqRbQsEK+txrtxwUBMpoH7YJr3mHqElOeQH1nzF616UJVZ7kXYP1OvIE74g HmVt6B8aOp6wiKbqHEYJKlpSy4FJk8PkPmQgTWFYbp67DQVyuI+dKagcdyDgodjMmkC7ULdIwJicr 4TjQDUMxv7a+I+Wt8qKXFeUYdJ09K3WQX1pmh+mgAd5VqI178VkNTxIy1eAWyWEZaszAd/4UB3G+7 iggOx0PxXIRAG1w6RjEUgm6Ag95BbxOZFZsHn70LKdTpxEMnszL57R77joXak1Dfw5oZHSbHRhE1i stfiysfw==; Received: from srv021.web.ichtushosting.com ([78.47.76.72]) by srv015.mail.ichtushosting.com stage1 with esmtp (Exim MailCleaner) id 1kPiiZ-0006Lj-TG for from ; Tue, 06 Oct 2020 10:53:08 +0200 Received: from ptr-fq9pjpjnzx2cyl830pe.18120a2.ip6.access.telenet.be (ptr-fq9pjpjnzx2cyl830pe.18120a2.ip6.access.telenet.be [IPv6:2a02:1812:c3c:3a00:ecd6:1223:165f:c252]) (Authenticated sender: brendt@stitcher.io) by srv021.web.ichtushosting.com (Postfix) with ESMTPSA id E957120F2C for ; Tue, 6 Oct 2020 10:53:05 +0200 (CEST) X-MailCleaner-return_path: brendt@stitcher.io X-MailCleaner-sender_address: brendt@stitcher.io X-MailCleaner-recipients: internals@lists.php.net Content-Type: multipart/alternative; boundary="Apple-Mail=_3064C139-8F44-425A-89D7-45A59CBCFB71" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) Date: Tue, 6 Oct 2020 10:53:04 +0200 References: <446c9894-191f-e53b-4534-31c4e7b91d7b@gmail.com> <881e2335-5f81-0d79-6a17-06bc20f14223@gmx.net> <873361ff-02c8-b9df-9b7a-c9e89e25a880@gmx.net> To: Levi Morrison via internals In-Reply-To: <873361ff-02c8-b9df-9b7a-c9e89e25a880@gmx.net> Message-ID: <7F014A40-2D47-4DA6-8A38-59518218F9CA@stitcher.io> X-Mailer: Apple Mail (2.3608.120.23.2.1) X-MailCleaner-TrustedIPs: Ok Subject: Re: [PHP-DEV] RFC: Support for multi-line arrow functions From: brendt@stitcher.io (Brent Roose) --Apple-Mail=_3064C139-8F44-425A-89D7-45A59CBCFB71 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 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 = the 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] >=20 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 well as my experience from an OSS maintainer point of view. Furthermore, the `use(*)` syntax misses the point of this proposal: it's = not about being able to use all variables from the outer scope, 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 = this list: it's clear that the PHP community _wants_ these changes: = 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.=20 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 = functional-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. >=20 > That is, until PHP 7.4. >=20 > PHP 7.4=E2=80=99s introduction of short lambdas is, as we=E2=80=99ll = see 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 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.=20 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.=20 Kind regards Brent [1] https://wiki.php.net/rfc/arrow_functions_v2 = =20 [2] https://leanpub.com/thinking-functionally-in-php = =20 > On 5 Oct 2020, at 12:39, Andreas Leathley wrote: >=20 > On 05.10.20 12:15, Deleu wrote: >> To me that seems like a great argument in favour of the proposal. If = you'll >> want all variables to be imported (which in this case makes = completely >> sense), then `fn() {}` or `fn() =3D> {}` is much less verbose and = inline with >> the mentality to reach for short closures. We reach for short = closures to >> avoid `use()` and convey that the outer process is intertwined with = the >> inner process. `fn()` allows to strengthen the concept that there's = no real >> separation between running SQL stuff in a `callable` that wraps a = database >> transaction. >=20 > Not necessarily: the arrow functions were specifically implemented for > very short anonymous functions with a return value. Making them more = and > more like the existing "function" syntax would lead to having two > different ways of defining anonymous functions that mainly = differentiate > themselves by including the parent scope by default or not. >=20 > I like the "function () use (*)" suggestion because it is explicit and > opt-in. A shorter syntax like "fn () {}" is less clear, and it could > lead to many people always using fn just because it is faster to write > (and less to think about), which then could lead to unintended side > effects because variables are being copied from the parent scope each > time. When you see a usage of "fn () {}" while reading code you would > not know if the person used it because it was faster to write, or if = the > parent scope variables are really needed. >=20 > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >=20 --Apple-Mail=_3064C139-8F44-425A-89D7-45A59CBCFB71--