Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113833 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 45059 invoked from network); 28 Mar 2021 16:17:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Mar 2021 16:17:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 66815180087 for ; Sun, 28 Mar 2021 09:13:55 -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,NICE_REPLY_A, 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-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 ; Sun, 28 Mar 2021 09:13:54 -0700 (PDT) Received: by mail-ed1-f46.google.com with SMTP id e7so11576853edu.10 for ; Sun, 28 Mar 2021 09:13:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=tcrxD6Fx5dMDugjEXfVHDrujZLvZgAYwTzKetfdRdrE=; b=BBaEmf0I/mH/NmSXDij0Ow4/pBwPTr1JbufjXbCAY1g0gZSrbk8skt/+i4jt753HjY OUMyNOoyQoITWwBipl2Xmrde9T3KHogp2Yke4eodpg50vBFr/TMo9DmJTWnSdjQR+rwi uBVJ3pO66xKZLfleyQ0TyI5DM2q9Z8I3O+cxMaftQdmUnSyHFjVigRjyv5cxGLGYWE5O hycA4i6P6me00JScJ/aSdnwPz3pJipZAo//bg65dSDKfZf3RaPgia5lYES/xunarjvUa nc53fuqA+ZJyoAiAqly+s3QrMvhATRDqiZRcdWTntr1BF/0g2YRMBasyLoQ/Xab6RTSh UdtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=tcrxD6Fx5dMDugjEXfVHDrujZLvZgAYwTzKetfdRdrE=; b=c7JsNsKjqjzbCjhHssfpvWfdIaze2SeRGUajZdGtgooFeqoXI9ynt4p68+5X5Vm1uD c+Uimx0G02E3L/CHrP1xRkz5P/lJ1YWLf8kJXCJoA+uNFxC1ek9iz9hbJeK39dnkRdDn MlCNNNy2HB/myM6+FLRh86n6whanr6ZJQpRWkMKeVOrXboX2x0SoJT2c8FFhu7vOoc70 Tmf4yXIg382ccwJDEagE45pBK07R9FDkljR1/n387ZIH4rHN2W4meFyBLnCMfe8iCyRb 2s//eGLgVog83vYtLCv5O9gsoLFEOKDGgoMGuFGsOiViSKWU2IubiBB5RsBAgRReWOde VGKg== X-Gm-Message-State: AOAM531DLX0Vy6dLLerzkjQjvtjDRZDD3rsqPiTKt2fOq8CImGS59r+q XMm3C4Pf9YIuwv0mfgY0PuPhIiqyTjE= X-Google-Smtp-Source: ABdhPJx6lDcGyMeSIdVKYBWyZ/XajroVXFaX4mwYJ1XiWkeZsBrGFvYMtnNg8QrnB243rNLTadovzg== X-Received: by 2002:a50:8524:: with SMTP id 33mr25169026edr.110.1616948030237; Sun, 28 Mar 2021 09:13:50 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id t15sm7620454edc.34.2021.03.28.09.13.49 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 28 Mar 2021 09:13:49 -0700 (PDT) To: internals@lists.php.net References: <88c9eb5f-f80c-4869-b7f8-1b58b9e2eaa3@www.fastmail.com> <43a2b198-ab3d-411a-b978-2924e6af4b13@www.fastmail.com> Message-ID: <7c4afb69-4c94-4dbe-ccda-b2159d936e26@gmail.com> Date: Sun, 28 Mar 2021 17:13:49 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <43a2b198-ab3d-411a-b978-2924e6af4b13@www.fastmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV] [RFC] Auto-capture multi-line closures and short functions take 2 From: rowan.collins@gmail.com (Rowan Tommins) On 25/03/2021 16:25, Larry Garfield wrote: > So in conclusion, it seems the reasons closures weren't auto-capture always were: > > 1) Possible performance concerns that are no longer relevant. > 2) Avoid surprise references. > 3) Allow users to capture by value or by reference. I wasn't involved in the discussion when anonymous functions were first added, but I was during the discussions that led to the current arrow functions. I think it's important context that multi-statement closures were originally included and explicitly removed, precisely because automatic capture was always controversial. It is perfectly reasonable to re-visit the topic now, but it is not, as some seem to be implying, one that has already been agreed in principle. Bob's original "Short Closures" RFC [1] in 2015 included both single expressions and full function bodies. As in subsequent discussions, some people thought implicit capture was a great feature, and others were concerned by it. Rasmus described it [2] as "breaking [a] longstanding basic tenet of the language". There were other reasons that RFC was not accepted, mostly around syntax, but several people in the voting thread [3] gave automatic capture as a reason for voting no. The subsequent "Arrow Functions" RFC [4] by Bob and Levi in 2017 explicitly removed multi-statement bodies from the proposal, citing feedback from previous discussions. Bob confirmed in the discussion thread [5] that this was a deliberate design choice, because requiring "use" for most Closures "vastly improves readability and debuggability". Rasmus agreed [6] that automatic capture was acceptable in the new RFC specifically because single-expression closures "don't typically need a local scope at all". Finally, in 2019 Nikita wrote a new version of the RFC [7] which again left out multi-statement bodies. During the discussion [8] he considered adding them back in, but felt it would "add a number of complications" which should be addressed in a future RFC. Several people who had previously expressed strong concerns about automatic capture voted "Yes" to Nikita's RFC . At least some presumably did so precisely because multi-statement bodies were not included. [1] https://wiki.php.net/rfc/short_closures [2] https://externals.io/message/87958#87969 [3] https://externals.io/message/88394 [4] https://wiki.php.net/rfc/arrow_functions [5] https://externals.io/message/98045#98069 [6] https://externals.io/message/98045#98108 [7] https://wiki.php.net/rfc/arrow_functions_v2 [8] https://externals.io/message/104693#104738 Regards, -- Rowan Tommins [IMSoP]