[swift-evolution] Deprecating Trailing Closures
James Campbell
james at supmenow.com
Thu Mar 24 11:15:07 CDT 2016
I think the feature should stay but we need community guidelines on when
and when not to use them.
*___________________________________*
*James⎥Head Of CEO*
*james at supmenow.com <james at supmenow.com>⎥supmenow.com <http://supmenow.com>*
*Sup*
*Runway East *
*10 Finsbury Square*
*London*
* EC2A 1AF *
On Thu, Mar 24, 2016 at 4:13 PM, William Dillon via swift-evolution <
swift-evolution at swift.org> wrote:
> On Mar 24, 2016, at 7:18 AM, Kurt Werle via swift-evolution <
> swift-evolution at swift.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.
>
>
> Agree.
>
> Another thing I like about trailing closures is that it allows me to make
> custom constructs that feel more like a part of the language. For example,
> I really love this extension for NSLock that I have:
>
> extension NSLock {
> func protect(action: (Void) -> Void) {
> self.lock()
> action()
> self.unlock()
> }
> }
>
> Now, whenever I need to use my lock, I can just do:
>
> peersLock.protect {
> outputString += "\(self.peers.count) peers:\n"
> for (_, peer) in self.peers {
> outputString += "\(peer)\n"
> }
> }
>
> To me, it looks cleaner to me to not have this paren dangling around at
> the end. On this one I’d definitely say that if you don’t like it, don’t
> use it. I don’t *think* that you’re forced to use it anywhere. It’s a
> hard sell to take it away from everyone.
>
> - Will
>
> _______________________________________________
> 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/20160324/73fb8e2d/attachment.html>
More information about the swift-evolution
mailing list