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

Howard Lovatt howard.lovatt at gmail.com
Mon Jan 25 22:54:11 CST 2016


Plenty of languages have something along these lines, however the syntax isn't standard and therefore I don't see that ?? is well established. How can it be, if languages all do their own thing? Note: I wasn't proposing eliminating the concept, just suggesting that it isn't worthy of an operator and an operator tends to be invisible in an expression where as a method call isn't. 

> On 26 Jan 2016, at 2:35 PM, Trent Nadeau <tanadeau at gmail.com> wrote:
> 
> Null/nil coalescing operators are used across several languages (see https://en.wikipedia.org/wiki/Null_coalescing_operator) The ?? operator in particular is also used for this purpose in C# and PHP 7.
> 
>> On Mon, Jan 25, 2016 at 9:43 PM, Howard Lovatt via swift-evolution <swift-evolution at swift.org> wrote:
>> I am no fan of the ?? operator since it tends to disappear in an expression, a bit like ?: does, and it fails the test of being well known or well established (see API guidelines). Also it isn't used often, therefore I would suggest a method, ifNil, added to Optional instead:
>> 
>>   x.ifNil(false)
>> 
>> > On 26 Jan 2016, at 1:32 PM, Craig Cruden via swift-evolution <swift-evolution at swift.org> wrote:
>> >
>> > I agree - ?? looks better — at least better than the example shown…. the suggested replacement looks messy and is not an improvement (occasional swift coder - as such I am less biased than other Swiftees).
>> >
>> >
>> >> On 2016-01-26, at 9:28:50, Erica Sadun via swift-evolution <swift-evolution at swift.org> 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.
>> >>
>> >> -- 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
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> 
> 
> -- 
> Trent Nadeau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160126/aeb7f9b3/attachment.html>


More information about the swift-evolution mailing list