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

Erica Sadun erica at ericasadun.com
Fri Jan 29 11:04:45 CST 2016


I know how frustrating it is to throw ideas out and not hear back. So here's my answer: I don't love this either. 
I think you're trying to fix something that is fundamentally not only not broken but pretty solid as it is currently deployed.

-- Erica

> On Jan 29, 2016, at 6:41 AM, Amir Michail <a.michail at me.com> wrote:
> 
> 
>> On Jan 29, 2016, at 5:03 AM, Thorsten Seitz <tseitz42 at icloud.com <mailto:tseitz42 at icloud.com>> wrote:
>> 
>> I agree with Erica. The ?? operator is very readable IMO.
>> 
>> Furthermore x?(false).isEmpty looks like it would evaluate false.isEmpty when x is nil which is certainly not what is intended.
> 
> What about this then: ??(false, x?.isEmpty)
> 
>> In addition it would not be clear which default should be used in case of multiple optional chainings happening, i.e. what should be the result of person?(false).address?.(true).isEmpty
>> 
>> -Thorsten
>> 
>> 
>> Am 26. Januar 2016 um 03:29 schrieb Erica Sadun via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>>:
>> 
>>> 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.
>>> 
>>> -- E
>>> 
>>>> On Jan 25, 2016, at 7:03 PM, Amir Michail via swift-evolution <swift-evolution at swift.org <mailto: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 <mailto:swift-evolution at swift.org>
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160129/26b7c2d4/attachment.html>


More information about the swift-evolution mailing list