[swift-evolution] Proposal: Replace ?? by an (optional) argument to ?

Ilya Belenkiy ilya.belenkiy at gmail.com
Sat Jan 30 11:52:02 CST 2016


I also think that the existing syntax is perfect. The fact that it's about
optionals and not Boolean values is the whole purpose of the operator, and
it feels very natural.

On Sat, Jan 30, 2016 at 12:28 PM Amir Michail via swift-evolution <
swift-evolution at swift.org> wrote:

> On Jan 30, 2016, at 11:31 AM, Thorsten Seitz <tseitz42 at icloud.com> wrote:
>
>
> Am 26.01.2016 um 03:30 schrieb Amir Michail via swift-evolution <
> swift-evolution at swift.org>:
>
>
> On Jan 25, 2016, at 9:28 PM, Erica Sadun <erica at ericasadun.com> wrote:
>
> Not loving this.  I'm quite happy with ??-coalescing and don't see
> a compelling reason it needs to be "cleaner". I find your suggested
> enhancement less readable. Looks like an optional chaining across
> a function.
>
>
> ?? puts the least important part of the expression in the most important
> position — namely, the end.
>
>
>
> I think that’s actually a very good place as it is the option that is
> considered last.
>
>
> After thinking about it some more, it’s not really the position that is
> the problem.
>
> I think the problems with ?? are as follows:
>
> * not specialized to a boolean context (i.e, it is too general for most
> cases)
> * “??" is too catchy for something this minor
> * true/false contain too many letters for something this minor
>
> I would like to type something like this:
>
> if x?.isEmpty || nil { … }
> if x?.isNotEmpty && !nil { … }
>
> So one might consider turning “|| nil” into a suffix, say |nil.
> Similarly, one might consider turning “&& !nil” into a suffix, say &!nil.
>
> So maybe:
>
> if x?.isEmpty |nil { … }
> if x?.isNotEmpty &!nil { … }
>
>
>
> -Thorsten
>
>
>
> -- E
>
> On Jan 25, 2016, at 7:03 PM, Amir Michail via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> Examples:
>
> * instead of x ?? false, you would have x?(false)
> * instead of x?.isEmpty ?? false, you would have x?(false).isEmpty
>
> I think this change would result in cleaner looking code.
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> 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/20160130/de282516/attachment.html>


More information about the swift-evolution mailing list