[swift-dev] Fixit for trailing closures

Erica Sadun erica at ericasadun.com
Tue Jul 5 21:57:18 CDT 2016



> On Jul 5, 2016, at 7:42 PM, Xi Ge via swift-dev <swift-dev at swift.org> wrote:
> 
>> 
>> On Jul 5, 2016, at 5:39 PM, Xi Ge via swift-dev <swift-dev at swift.org <mailto:swift-dev at swift.org>> wrote:
>> 
>>> On Jul 5, 2016, at 5:19 PM, Ben Langmuir <blangmuir at apple.com <mailto:blangmuir at apple.com>> wrote:
>>> 
>>>> 
>>>> On Jul 5, 2016, at 4:34 PM, Xi Ge via swift-dev <swift-dev at swift.org <mailto:swift-dev at swift.org>> wrote:
>>>> 
>>>> Hi Swift-devs,
>>>> I have tried to add a fixit to help developers using trailing closures more, motivated by my observation during WWDC that some developers 
>>>> do not even realize that we have such a feature. In my opinion, trailing closures are more concise, and once you get used to it, more readable; 
>>>> therefore users should adopt trailing closures whenever doing so introduces no ambiguity.


I prefer trailing closures for -> Void signatures and in-line closures for anything (notably sequences and collections) that is likely to be iterated through or chained functionally. I also prefer inline closures for items that have multiple states for callback (completion handlers, error handlers, etc, where there is going to be a test of some kind -- we don't have a Result type but if we did, it would fall here -- and contains error/value pairs) and trailing closures for no-state-will-execute such as GCD.

-- E

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160705/06c0d9b0/attachment.html>


More information about the swift-dev mailing list