[swift-evolution] Please remove obscure "!" requirements for implicitly unwrapped optionals

Chris Lattner clattner at apple.com
Fri Dec 4 19:35:32 CST 2015


On Dec 4, 2015, at 5:00 PM, Per Melin <p at greendale.se> wrote:
>> Xcode "fixes" the last line like this:
>> 
>>     if (a != nil) { }
> 
> Huh ok.  Out of curiosity, why are you using IUOs for this?
> 
> I will leave that question to Amir who created this thread. I try to avoid IUOs altogether. I only found the above when trying to figure out what the heck he was talking about.
> 
>  
> I’m interested in (continuing to ) dramatically reduce the prevalence of IOUs in code (eliminating the need to use them), and reduce their power in various ways.  IUOs are one of the biggest sources of surprising behavior in Swift, and while they were a necessary feature to start with, their importance is going down over time.
> 
> What surprised me was the IIUOs. I did not expect Swift to happily help me shoot myself in the foot quite so easily as this.
> 
> func isNegative(i: Int?) -> Bool {
>     return i < 0
> }
> 
> (No, I have never actually written code like this. I can't tell how likely it is that I would make this mistake.)

This is a separate problem.  One of the things we plan to discuss (once things settle down a bit) is how to narrow the implicit conversion from T to T? in cases like this.  This implicit promotion, as well as the T <-> T! promotions are problematic in a number of ways, and we need a holistic solution to them.  

We have several specific ideas, but Joe Pamer is driving the effort and he is preoccupied with personal things for the next several weeks.

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151204/4f45344a/attachment.html>


More information about the swift-evolution mailing list