[swift-evolution] [Pitch] Introducing the "Unwrap or Die" operator to the standard library
david at hartbit.com
Wed Jun 28 16:30:52 CDT 2017
> On 28 Jun 2017, at 17:35, Ben Cohen via swift-evolution <swift-evolution at swift.org> wrote:
>> On Jun 28, 2017, at 6:03 AM, Erica Sadun via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> In general, does everyone prefer `?? () -> Never` or `!! () -> Never`? I can argue both ways, with the goal in reading code as "unwrap or die".
> Personally, I strongly prefer `foo !! "explanation"` over `foo ?? fatalError()`. I don’t think adding another operator for what is a very common need is a concern, and is easier to read at a glance than the ??/fatalError combo. There is a bit of cognitive dissonance
Actually, the cognitive dissonance argument is a strong one. Its true that ?? doesn’t evoke trapping.
> between ??, a normally-fluffy nonthreatening defaulting operator, and fatalError, a scary beware operator. `!!` OTOH matches `!` in clearly flagging the unwrap as unsafe and that your program will exit. I also think it would be easier to explain `!!` to beginners as part of a wider story explaining optionals in general, unwraps, what `nil` means and what `!` means etc. Whereas `foo ?? Never` requires a lot of heavy lifting to understand how/why it works – we might all understand it, but that understanding is built on a lot of foundational understanding.
> I also think a `Never` type would be very useful. Just that for this particular case, `!!` is still worth adding too.
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution