Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117922 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 58587 invoked from network); 12 Jun 2022 19:42:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jun 2022 19:42:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 572E21804AF for ; Sun, 12 Jun 2022 14:29:28 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 12 Jun 2022 14:29:27 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 6A09E5C00FB for ; Sun, 12 Jun 2022 17:29:27 -0400 (EDT) Received: from imap52 ([10.202.2.102]) by compute1.internal (MEProxy); Sun, 12 Jun 2022 17:29:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1655069367; x= 1655155767; bh=kyLqnBTTiFY+3g98zkykUitzIrQpgCyFhM+BSb5qBU8=; b=e cuSC0z6XZfqSdWGd77qX02Gw0yi2X0qwpyqp8NirRiigXma3IdErYEJCVPFFRHJG /Gqp3ksgimI5O40zXZ2PiwcXEPLQU3HfLbJ9iUnGXfEnIDMZofjiMzESTSQ1GXi6 +WtkicFejQ7tc3qrgXj3XAcVaYQSFsgAahSnGLE8duI8P7bJHNttwqnJ3ekQYkBR NTo5JMDhlJSF6e086/dmLZgzdfS7AqRtnidtvZQJA9t/JFDu32kAtspEwoL2g8u7 wUnuJAga4fNVj17AX5cMpXvsFiujSVzGabRWwrFalrTKVKJt2O/AKN1GYbZkPUDV eNbyAR1z7nv9BH8+ZcF/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1655069367; x=1655155767; bh=kyLqnBTTiFY+3g98zkykUitzIrQp gCyFhM+BSb5qBU8=; b=OQ9SjnwSasA++o4OanLEwwpcRwyCSx18/cbIrYNOtHjM 3wAzNbystKPX++/z0bMdW4v2Km126gDc6sOWeETxIFtTroKvo/vES5QDnjixsYum 0k1ZM/rQdOoMmn/myG10e3kEFQ0moIA1LLr3KbgCHxQhOEzu9K5oid0ljsrP1bzn kIl691EI/og2GvjzfM0Dl4SpvLGeOH2p4P/VunM48kuqI45dfCFpzWA7co3q9vE9 sTCTZKTDc3rLVN5BAaNBz1ZXJaHItDs/JA8Lf2quP35p7GKmmcljsSAsg+K+U2e8 Q5hiO881Go6jC+GnoAGjbpdXCPF0gvawry/l5d8u7A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudduhedgudehkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefg ffekudevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 20C46C6008A; Sun, 12 Jun 2022 17:29:27 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-692-gb287c361f5-fm-20220603.003-gb287c361 Mime-Version: 1.0 Message-ID: <85cd3b46-379a-4f0e-b78d-3bd000a349e1@www.fastmail.com> In-Reply-To: <25caf251-d9a4-ba57-9e23-7f0ccd914cf3@gmail.com> References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> <2279cbd2-fcfe-460f-97f9-0029b7b043bb@www.fastmail.com> <25caf251-d9a4-ba57-9e23-7f0ccd914cf3@gmail.com> Date: Sun, 12 Jun 2022 16:29:06 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Short Closures 2, aka auto-capture take 3 From: larry@garfieldtech.com ("Larry Garfield") On Sun, Jun 12, 2022, at 3:44 PM, Rowan Tommins wrote: > On 12/06/2022 18:21, Larry Garfield wrote: >> The primary target of this RFC is people writing 2-4 line closures that import 1-2 variables > > > The first half of that sentence I was expecting - although as I've > already said, I think the chosen syntax suggests strongly that the RFC > is really targeting *all* closures, not any subset of them. > > The second half makes much less sense. If you are only importing 1 or 2 > variables, is writing their names really that big a burden? > > Several of the conversations I've had on this in the past have been very > explicitly about the burden of large numbers of captures; if that's > really as rare as you suggest, it makes me wonder why we're even bothering. > > Regards, Disclaimer: My own view, I cannot speak for Nuno or Arnaud. If you're capturing a very large number of variables, then I would view that as a code smell. "Very large" is subjective, of course, and there's some context to it. The two main use cases I see myself using are A) 2-3 liners that use 1-3 variables from scope, so it's dead obvious what they are. In this case, the extra use clause doesn't really add much beyond visible noise. B) An entire method body is a closure that is being returned, or inlined into an inTransction() call or something like that. In this case, basically all method parameters would be captured, and it would be on the very previous line, so no matter how many there are (more than ~5 is probably a problem with the method, not with the closure), they're redundant and don't tell you anything that isn't already self-evident. So the burden is in having to think about redundant syntax at all, plus having more redundant text that has to be read in the future. Even with use(*) or use(...) or whatever, that's better than the status quo but is still just more boilerplate that would have to be added/removed when switching from a one line short lambda (side note: This is the term I always use; I basically never use "arrow function". I don't know how typical that is) to a 2-line closure when refactoring. --Larry Garfield