Re: [RFC] Short Closures 2, aka auto-capture take 3
| From: | Larry Garfield | Date: | Sun, 12 Jun 2022 20:25:54 +0000 |
| Subject: | Re: [RFC] Short Closures 2, aka auto-capture take 3 | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-117920@lists.php.net to get a copy of this message | ||
On Sun, Jun 12, 2022, at 12:54 PM, Mark Baker wrote:
> On 12/06/2022 19:21, Larry Garfield wrote:
>> On Thu, Jun 9, 2022, at 11:34 AM, Larry Garfield wrote:
>>
>> A little data:
>>
>> I used Nikita's project analyzer on the top 1000 projects to get a rough sense of how
>> long-closures are used now. All usual caveats apply about such survey data. I was specifically
>> looking at how many
use statements a closure typically had, and how
>> many statements it typically had. Mainly, I am interested in how common "really long closures
>> where the developer is likely to lose track of what is and isn't closed over" are.
>>
>> Total closures: 20052
>> Total used variables: 11534
>>
> Did many of those closures use "pass by reference" in the use clause,
> because that's one real differentiator between traditional closures and
> short lambdas. There's also the fact that use values are bound at the
> point where the closure is defined, not where it's called (if they even
> exist at all at that point), although that's probably more difficult to
> determine.
New run to check for that:
Total used variables: 11534
ByRef used variables: 1833
So around 13% of used variables are by-ref, and thus would need to be explicitly used even with the
new syntax.
> There's also the fact that use values are bound at the
> point where the closure is defined, not where it's called (if they even
> exist at all at that point), although that's probably more difficult to
> determine.
I... don't see what relevance that has? The potential for confusion is at the definition
point, not call point. If a closure is used inline then those are the same place, but if
they're not, it's only the definition point that is relevant at the moment.
--Larry Garfield