[swift-evolution] Deprecating Trailing Closures

Alex Blewitt alex.blewitt at gmail.com
Fri Mar 25 03:40:57 CDT 2016



> On 25 Mar 2016, at 08:10, Haravikk via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On 24 Mar 2016, at 21:08, Howard Lovatt <howard.lovatt at gmail.com> wrote:
>> 
>> I use trailing closures all the time because I find the brackets too noisy, like ; at the end of a line is too noisy. The sort of code I use is:
>> 
>>     let foo = myArray
>>         .filter { $0 & 1 == 1 }
>>         .map { $0 + 1 }
>>         .reduce(0) { $0 + $1 } 
> 
> This doesn’t really seem much neater or more readable to me than:
> 
> 	let foo = myArray
> 		.filter({ $0 & 1 == 1 })
> 		.map({ $0 + 1 })
> 		.reduce(0, { $0 + $1 })
> 
> While they may add a small amount of noise, in the latter case the parenthesis clarifies that each is a method, and what all of its arguments are, and don’t use any custom syntax. Of course this assumes that .reduce() would have an optional label on its closure argument.

On the other hand, I find the addition of the parenthesis makes it less readable than the one without. So please don't assume that what is equally readable for you applies to everyone else. 

Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160325/4e7eccd3/attachment.html>


More information about the swift-evolution mailing list