[swift-evolution] [Pitch] Improving capturing semantics of local functions

Mike Kluev mike.kluev at gmail.com
Tue Nov 14 23:39:37 CST 2017


On 14 November 2017 at 21:36, Mike Kluev <mike.kluev at gmail.com> wrote:

>
> it might cover well over 90% of use cases (by my "pessimistic"
> estimate)... if someone has a quick way to scan and analyse, say, github
> swift sources we may even know that current percentage number of real life
> usage.
>

i did a quick & dirty search on github (queries below). here are some stats:

1) "weak var" - 946K hits

2) "weak self" - 168K hits

3) "weak" - 1127K hits

the summ of "weak var" + "weak self" = 1114K hits

number of "weak" - 1114K = 13K

let's assume this 13K is for weak "something" which is not "self"

number of "weak something" + "weak self" = 181K

"weak self" = 168K / 181K = 93%

"weak something" = 13K / 181K = 7%

the search queries for those interested:

https://github.com/search?utf8=✓&q=%22weak+var%22+filename%3A.swift&type=Code
<https://github.com/search?utf8=%E2%9C%93&q=%22weak+var%22+filename%3A.swift&type=Code>
https://github.com/search?utf8=✓&q=%22weak+self%22+filename%3A.swift&type=Code
<https://github.com/search?utf8=%E2%9C%93&q=%22weak+self%22+filename%3A.swift&type=Code>
https://github.com/search?utf8=✓&q=%22weak%22+filename%3A.swift&type=Code
<https://github.com/search?utf8=%E2%9C%93&q=%22weak%22+filename%3A.swift&type=Code>

note that you have to rerun the search multiple times until it settles
around some number.
also note, you can't easily use [ ] or other punctuation in github builtin
search.

the stat suggests that in 90%+ real-life cases [weak self] is used so the
"weak func" syntax sugar is worth to consider as an addition to this
proposal.

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171115/977e9823/attachment.html>


More information about the swift-evolution mailing list