[swift-evolution] [Review] SE-0103: Make non-escaping closures the default
Jean-Daniel Dupas
mailing at xenonium.com
Thu Jun 23 17:15:37 CDT 2016
-1 for the proposal too
@nonescaping is more restrictive than escaping closure. You can’t pass a non escaping closure to a method that expects one, while the reverse is possible.
Nowadays, a method without any annotation defaults to be able to do anything. If we switch to non-escaping as the default, a method without annotation would be restricted in what it can do with the closure. That’s why I don’t think this is a good move.
for example:
func myfunc(closure: () -> Void) {
stdlibfunction(closure)
}
Today, whatever the stdlib function annotation is, it will compile. By reversing the annotation, that code may compile or not depending the stdlib function annotation.
Forcing the newcomer to learn advanced optimization technic to be able to write a simple function is very bad IMHO.
> Le 23 juin 2016 à 23:06, Diego Sánchez via swift-evolution <swift-evolution at swift.org> a écrit :
>
> * What is your evaluation of the proposal?
>
> -1
>
> I find myself using 3 types of closures:
> - Algorithm-like (filter, map etc.). non-escaping
> - Completion closures: asynchronous operations: network requests, many cocoa APIs, background image processing. escaping
> - Data/dependency providers: userProvider(forId id: String) -> User. escaping (ok, can be non-escaping sometimes too)
>
> In the codebases I'm working with, escaping closures predominate clearly; and most of the non-escaping ones refer to usages of the standard library.
>
> Another point comes when changing things. Consider the following code:
>
> func doSomething(closure: () -> Void) {
> self.doSomething2(closure)
> }
>
> func doSomething2(closure: () -> Void) {
> self.doSomething3(closure)
> }
>
> func doSomething3(closure: () -> Void) {
> closure()
> }
>
> If non-escaping is the default, and for some reason doSomething3's closure needs to change to escaping, then I would have to change all the callers as escaping.
>
> To sump up, I see @noescape as something to opt-in for performance reasons (or better static analysis as it was mentioned during the initial discussion) but I don't think it's a good default.
>
> * Is the problem being addressed significant enough to warrant a change to Swift?
> I don't think there's a problem that needs to be fixed.
>
> * Does this proposal fit well with the feel and direction of Swift?
> Not really. I think escaping is a safe good default that works for all cases.
>
> * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
> NA
>
> * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
> Followed the discussion and read the proposal carefully.
>
>
> 2016-06-22 6:03 GMT+01:00 Chris Lattner via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>>:
> Hello Swift community,
>
> The review of "SE-0103: Make non-escaping closures the default" begins now and runs through June 27. The proposal is available here:
>
> https://github.com/apple/swift-evolution/blob/master/proposals/0103-make-noescape-default.md <https://github.com/apple/swift-evolution/blob/master/proposals/0103-make-noescape-default.md>
>
> Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at
>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>
> or, if you would like to keep your feedback private, directly to the review manager.
>
> What goes into a review?
>
> The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:
>
> * What is your evaluation of the proposal?
> * Is the problem being addressed significant enough to warrant a change to Swift?
> * Does this proposal fit well with the feel and direction of Swift?
> * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
> * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
>
> More information about the Swift evolution process is available at
>
> https://github.com/apple/swift-evolution/blob/master/process.md <https://github.com/apple/swift-evolution/blob/master/process.md>
>
> Thank you,
>
> -Chris Lattner
> Review Manager
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160624/a3485102/attachment.html>
More information about the swift-evolution
mailing list