[swift-evolution] Deprecating Trailing Closures

Haravikk swift-evolution at haravikk.me
Thu Mar 24 10:14:54 CDT 2016


> On 24 Mar 2016, at 14:18, Kurt Werle <kurt at circlew.org> wrote:
> 
> Coming from ruby, I'm quite fond of trailing closures.  I couldn't really give you a concrete reason why - putting them in the ()'s really isn't that big a deal.  But I'll say that I move them outside every single time...
> 
> I will say that your examples are the most trivial possible and that the more complex the closure (describing context variables and return types, throws, etc) the uglier it seem to me to put it inside parens.

Perhaps, but if you’re getting that onto a single line then it starts to look ugly regardless IMO, whereas splitting it across multiple lines isn’t really any different with or without being in the parenthesis, except that the closing parenthesis at least clarifies that it was a method you’re closing, for example:

	var modifier = true
	let foo = myArray.map({
		var result = $0
		if modifier { result = -result }

		modifier = !modifier
		return result
	})

I dunno, I guess I’m just struggling to find cases in my own code where they really offer much of an advantage to justify having a distinctly different way of doing things, with the ambiguity and inconsistency that represents, which is why I’ve brought it up to discuss; i.e- do we use them just because they exist? Trivial aesthetic difference? Personal preference only?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160324/0d4dfbbd/attachment.html>


More information about the swift-evolution mailing list