Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113774 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 21720 invoked from network); 25 Mar 2021 15:06:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Mar 2021 15:06:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7BB1E1804D8 for ; Thu, 25 Mar 2021 08:02:45 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (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 ; Thu, 25 Mar 2021 08:02:44 -0700 (PDT) Received: by mail-qt1-f172.google.com with SMTP id m7so1817190qtq.11 for ; Thu, 25 Mar 2021 08:02:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=tZWYJDgVtvh00ZwKwDH8cV4Sd1PXKb5LB4++eNzGUzo=; b=L5sq0bhzDl29La+CV1Jk30ZWyALjYu86jIISkGmi8WajRaniae4srXoi+aZTvHoGbC i18R1WRcfKA0qvs21hHc2MAllfe7uvGxDS2/DXAHkyh1nAiNOrrEEzHiOrFBBTQgEKJ2 EkuyYmUANBlravM2CS021NCbQLHhiJx6f+3qXd6oNC3SlhikRCa2HMu107MfynhaHiu7 UnhPkyiwSko9OWmTdpYs7AIEjQmx4uR1w4m79Cl7r34YN26GZbcgtgO/O9bqPfy2SVTb 59Ug0mXYGO/sm8fEfBCaZnN/9slgKoOv58hSxjnVI9lCHe/VYKBbZVZ7Y7MTQUW6bkc1 TZvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=tZWYJDgVtvh00ZwKwDH8cV4Sd1PXKb5LB4++eNzGUzo=; b=iiKVsxw0k7oWsrBUbQyB7efpF+4jawyBLnt4E8gSNVHvVB2wBBacNh4cy59HagBtdU Rcz02do/oODOsH1m5SUoV5Gcy2i0PBXdXGLD7itb+WQxajtmtYIBMnWd+RHPmoKJf5ds 24LhlNyljLn4VmQXSL3xjFg5PkEAJpkHQSg9BjGUSHRnv4BeDLnOzfNxo0GUX4oH4r2V 0igHNCx6C9CwG8KdhoputUGLg99uuw8Xf6nCcKC7dOIpiTUkb9UfZQ7IwNqhEcMoRPmW GaOpW1eSWOEM/IGB+N++CD+/Rba8afNrZmkaSBEZyePoZSuDqBDHDLaB/SQh4AkIR0jE ph0w== X-Gm-Message-State: AOAM532WHxAFWV+1uLMOY2JOSzIQERfqXwpFdWvETw03b9qDPYFKxc+/ uLkGH3CH8Uz8F7lSq89fcbME+g== X-Google-Smtp-Source: ABdhPJzukaF64SmDpfI5ykuoqODs/CTDzMTw6EZt+vuf/SZU9cMNjS9vGqYKjuLw+gRwumGNBzffyw== X-Received: by 2002:ac8:68d:: with SMTP id f13mr8003441qth.300.1616684564050; Thu, 25 Mar 2021 08:02:44 -0700 (PDT) Received: from [192.168.1.239] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id q2sm4342336qkq.59.2021.03.25.08.02.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Mar 2021 08:02:43 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) In-Reply-To: Date: Thu, 25 Mar 2021 11:02:39 -0400 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <36E45DD6-E2BD-4801-BAAE-4355C83D1AC3@newclarity.net> References: <88c9eb5f-f80c-4869-b7f8-1b58b9e2eaa3@www.fastmail.com> <4DC3B66E-A91A-4AA9-8872-8EE9DE92C2D4@cschneid.com> <8c72c162-83c0-7c7f-2fa7-4fbe3fb30a4a@gmail.com> <605bae82.1c69fb81.f49f7.d11eSMTPIN_ADDED_MISSING@mx.google.com> <919e30e7-3e5e-d955-7bb4-1e1b5825cdd1@gmail.com> <635DD146-FC6F-4991-8D2C-5A6B492722D5@newclarity.net> <734f12de-da98-6b76-c2fe-8682f4d177aa@gmail.com> To: Rowan Tommins X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] [RFC] Auto-capture multi-line closures and shortfunctions take 2 From: mike@newclarity.net (Mike Schinkel) > On Mar 25, 2021, at 10:41 AM, Rowan Tommins = wrote: >=20 > On 25/03/2021 12:31, Nuno Maduro wrote: >=20 >> The reason why we believe the vast majority of PHP Developers are = going to >> appreciate this RFC is because multi-line short closures (aka >> Auto-capturing multi-statement closures) *are more simple, shorter to >> write, and prettier to read *=E2=80=94 and the community love these = changes as >> proven on "property promotions", "one-line short closures", etc. >=20 >=20 > My main point was that the RFC needs to spell out this argument, = rather than taking it for granted that everyone agrees on "those = situations where that is warranted". >=20 > Most of the current text should be summarised in a "syntax choices" = section somewhere near the end. I would like to see much more space = devoted to: >=20 > * Why we need this feature. What has changed since it was left out of = the arrow functions RFC? What problems is it addressing? Why do you = think it is the best approach to those problems? > * The exact semantics proposed: How will the variables to be captured = be determined? Will it distinguish variables which are written before = they're read, and if so how is that defined? Can auto-capturing closures = be nested, i.e. will "fn() { return fn() { echo $a; } }" capture $a from = the outermost scope? And so on... >=20 >=20 >> Besides, one advantage of this RFC is that it is consistent with the >> current syntax of the language and with the short-functions RFC[2]. = For >> example, by proposing that "fn" keyword indicates a function will >> auto-capture variables, by value. >=20 >=20 > While it's a cute rationalisation, there's no intuitive reason why = "fn" should have that meaning; we could pick any aspect of the current = arrow function syntax and say "the 'fn' keyword means that". >=20 >=20 >=20 >> On the other hand "use (*)" has no usages / or current meaning in the >> language. >=20 >=20 > This is a straw man argument. I could equally say that "fn() { } has = no usages or current meaning in the language" - of course it doesn't, we = haven't added it yet! >=20 > The "function use() {}" part of "function use(*) {}" has a = well-established meaning, and "*" to mean "everything" is a notation = developers are likely to be very familiar with. >=20 > The two disadvantages I see with using "fn" as proposed are: >=20 > * Because it's shorter, people will decide it's the "better" version, = when they don't actually need any variable capture. An explicit syntax = like "use(*)" instead makes this a deliberate choice. And yet adding " use (*)" makes the syntax longer, which goes against = one of the goals many people have for it: to be shorter. > * There is no obvious way to expand it to support any by-reference = capture, which is something people have previously expressed a desire = for. Can you please clarify why "function(...) use(...) {...}" can't be their = solution when someone needs by-reference capture? -Mike P.S. BTW, if we *had* to enable by-ref for "fn(...)" then I would argue = it should be a terse syntax, e.g.: $callable =3D fn()(&$foo) =3D> $foo=3D bar();