<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>I've been bit by this many times. A warning would really have helped me.</div><div><br>On 20 May 2016, at 07:06, Krystof Vasa via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div class="">Sorry, my previous example didn't use the string interpolation, it should be</div><div class=""><br class=""></div><div class="">print("<a href="http://apple.com\(myurl.path)" class="">http://apple.com\(myURL.path)</a>").</div><br class=""><div><blockquote type="cite" class=""><div class="">On May 20, 2016, at 7:04 AM, Dan Appel &lt;<a href="mailto:dan.appel00@gmail.com" class="">dan.appel00@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Thats a fair solution. I still disagree, but not as strongly.</div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Thu, May 19, 2016 at 10:01 PM Krystof Vasa &lt;<a href="mailto:kvasa@icloud.com" class="">kvasa@icloud.com</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">With this proposal in place:<div class=""><br class=""></div><div class="">1) The user would type print(myURL.path).</div><div class="">2) The compiler will immediately issue a warning about printing an optional - the user would hence learn about optionals *before* the code is run.</div><div class="">3) If he ran the code anyway, he'd still get Optional(/iphone/) anyway.</div><div class="">4) Xcode would offer a Fix-It, adding .debugDescription to the optional, getting Optional(/iphone/) on the anyway, yet again.</div><div class=""><br class=""></div><div class="">I'm not saying *removing* the current behavior, but adding a warning for this - you'd get the same result ignoring the warning and applying the Fix-It, but you'd have control over this.</div></div><div style="word-wrap:break-word" class=""><div class=""><br class=""></div><div class=""><div class=""><blockquote type="cite" class=""><div class="">On May 20, 2016, at 6:48 AM, Dan Appel via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><div dir="ltr" class="">&gt;google for swift print optional stackoverflow. I think that kind of speaks for itself.<div class=""><br class=""><div dir="ltr" class=""><div class="">I think this is actually an example of why the current behavior is a <i class="">good</i>&nbsp;thing. I did just google that and the top comment of the first result explains what an optional is. That is very good and encourages beginners to understand how optionals work under the hood. If you hide that from them, they will only be even more confused when they see just the string "nil" pop up when it previously was showing the correct value.</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Thu, May 19, 2016 at 9:36 PM Krystof Vasa via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">BTW - google for swift print optional stackoverflow. I think that kind of speaks for itself.<br class="">
<br class="">
&gt; On May 19, 2016, at 6:07 PM, Jeremy Pereira via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">
&gt;<br class="">
&gt; -1<br class="">
&gt;<br class="">
&gt; This seems to me like crippling string interpolation just because sometimes we make mistakes. 99% of the time, if I interpolate an optional, it’s because I want it that way. I don’t want to have to put up with a warning or write the same boilerplate 99% of the time just to flag up the 1% more easily. Sorry.<br class="">
&gt;<br class="">
&gt;&gt; On 18 May 2016, at 19:50, Krystof Vasa via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">
&gt;&gt;<br class="">
&gt;&gt; The string interpolation is one of the strong sides of Swift, but also one of its weaknesses.<br class="">
&gt;&gt;<br class="">
&gt;&gt; It has happened to me more than once that I've used the interpolation with an optional by mistake and the result is then far from the expected result.<br class="">
&gt;&gt;<br class="">
&gt;&gt; This happened mostly before Swift 2.0's guard expression, but has happened since as well.<br class="">
&gt;&gt;<br class="">
&gt;&gt; The user will seldomly want to really get the output "Optional(something)", but is almost always expecting just "something". I believe this should be addressed by a warning to force the user to check the expression to prevent unwanted results. If you indeed want the output of an optional, it's almost always better to use the ?? operator and supply a null value placeholder, e.g. "\(myOptional ?? "&lt;&lt;none&gt;&gt;")", or use myOptional.debugDescription - which is a valid expression that will always return a non-optional value to force the current behavior.<br class="">
&gt;&gt;<br class="">
&gt;&gt; Krystof<br class="">
&gt;&gt;<br class="">
&gt;&gt; _______________________________________________<br class="">
&gt;&gt; swift-evolution mailing list<br class="">
&gt;&gt; <a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
&gt;&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
&gt;<br class="">
&gt; _______________________________________________<br class="">
&gt; swift-evolution mailing list<br class="">
&gt; <a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div></div></div><div dir="ltr" class="">-- <br class=""></div><div class=""><div dir="ltr" class=""><div class=""><div class="">Dan Appel<br class=""></div></div></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></blockquote></div><div dir="ltr" class="">-- <br class=""></div><div class=""><div dir="ltr" class=""><div class=""><div class="">Dan Appel<br class=""></div></div></div></div>
</div></blockquote></div><br class=""></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>