[swift-evolution] guard let x = x

David Goodine dmgoodine at gmail.com
Wed Oct 26 06:40:43 CDT 2016

Hey all,

As usual, apologies if this horse was beaten ages ago before I joined the mailing list, but thought I would bring this up.

I was typing the above (for the hundredth time) the other day and I was wondering whether it might be worth considering offering a shorter syntax:

guard let x, y, z else {…}

I was never convinced why implicit nil checks (i.e. if x {…}) were such a bad thing.  But now in Swift it seems that it would be much more convenient to be able to simply skip the assignment part of the expression and define the above as guaranteeing and unwrapping x, y and z in the appropriate scope.

I think with such powerful and already compact expressions now wanting to get on the same line,adding this would make the language even more compact and elegant.  It could be added as a non-source-breaking change, still allowing x = x for those who prefer it, but could significantly tighten up such uses, which I’m finding are ubiquitous in my code.

Any thoughts?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161026/018dcca2/attachment.html>

More information about the swift-evolution mailing list