[swift-evolution] [Review] SE-0056: Allow trailing closures in `guard` conditions

David Hart david at hartbit.com
Fri Apr 1 16:15:04 CDT 2016


> What is your evaluation of the proposal?
-1 I admire the goal of making trailing closures usably in guard, but I do not like the inconsistency between guard and if. I also never liked the inconsistency with the else keyword in guard. Bother those reasons means that I’m worried that this will increase the cost of transforming guards into ifs, as can be quite frequent when refactoring code.

For example, transforming:

guard collection.contains { $0.predicate } else {
    return
}

Would require more modification:

if !collection.contains({ $0.predicate }) {
    return
}

> Is the problem being addressed significant enough to warrant a change to Swift?
I do not think so.

> Does this proposal fit well with the feel and direction of Swift?
I think this proposal has the danger of adding inconsistency, which is opposite to the direction of simplification for Swift 3.0

> If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
Ruby uses keywords the conditional expression for the body of control structures (similar to guard’s else). Perhaps if Swift also adopted those would we be able to implement trailing closures in conditional expressions everywhere:

if condition then {
} else {
}

while condition do {
}

switch expression on {
}

> How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
A thorough read and long thought.

> 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,
> 
> Doug Gregor
> 
> Review Manager
> 
> _______________________________________________
> 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/20160401/9757321a/attachment.html>


More information about the swift-evolution mailing list