<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On Jun 28, 2017, at 8:32 PM, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class="">I would like to see an example where this string plausibly makes the difference between having to hunt down the code and not have to do so. I do not believe that "array must not be empty" or "array guaranteed non-empty" is such an example, and I cannot myself imagine another scenario where it would make such a difference.</div></div></div></div></div></blockquote><div class=""><br class=""></div>You needn’t imagine. There was one up-thread:<div class=""><br class=""></div><div class=""><span style="font-family: HelveticaNeue;" class=""> let paramData = params.data(using: String.Encoding.ascii)!</span><br style="font-family: HelveticaNeue;" class=""></div><div class=""><span style="font-family: HelveticaNeue;" class=""><br class=""></span></div><div class=""><span style="font-family: HelveticaNeue;" class="">Huh? Why is force unwrap safe here? OK, the code plainly says the author thinks that `params` must already be ASCII, but why is that a safe assumption? What reasoning lead to that? What other sections of the code does that reasoning depend on? If we get a crash on this line of code, what chain of assumptions should we follow to discover the change that broke the original author’s reasoning behind the force unwrap?</span></div><div class=""><span style="font-family: HelveticaNeue;" class=""><br class=""></span></div><div class=""><span style="font-family: HelveticaNeue;" class="">This is a job for a comment:</span></div><div class=""><span style="font-family: HelveticaNeue;" class=""><br class=""></span></div><div class=""><div class=""><span style="font-family: HelveticaNeue;" class=""> </span><span style="font-family: HelveticaNeue;" class="">let paramData =</span><span style="font-family: HelveticaNeue;" class=""> </span><span style="font-family: HelveticaNeue;" class="">params.data(using: String.Encoding.ascii)! // </span><span style="font-family: HelveticaNeue;" class="">params</span><span style="font-family: HelveticaNeue;" class=""> is </span><span style="font-family: HelveticaNeue;" class="">URL-escaped, thus already</span><span style="font-family: HelveticaNeue;" class=""> ASCII</span></div><div class=""><font face="HelveticaNeue" class=""><br class=""></font></div><div class=""><font face="HelveticaNeue" class="">Aha, it’s URL escaped.</font></div><div class=""><span style="font-family: HelveticaNeue;" class=""><br class=""></span></div><div class=""><span style="font-family: HelveticaNeue;" class="">That comment does not repeat information already stated in the code itself. It does what any good comment does: it explains </span><span style="font-family: HelveticaNeue;" class="">intent, </span><font face="HelveticaNeue" class="">context, and rationale. It doesn’t restate _what_, but rather explains _why_.</font></div><div class=""><span style="font-family: HelveticaNeue;" class=""><br class=""></span></div><div class=""><font face="HelveticaNeue" class="">For those who appreciate comments like that, this proposal simply allows them to surface at runtime:</font></div><div class=""><span style="font-family: HelveticaNeue;" class=""><br class=""></span></div></div><div class=""><span style="font-family: HelveticaNeue;" class=""> </span><span style="font-family: HelveticaNeue;" class="">let paramData =</span><span style="font-family: HelveticaNeue;" class=""> </span><span style="font-family: HelveticaNeue;" class="">params</span><span style="font-family: HelveticaNeue;" class="">.data(using: String.Encoding.ascii) !! "</span><span style="font-family: HelveticaNeue;" class="">params</span><span style="font-family: HelveticaNeue;" class=""> is </span><span style="font-family: HelveticaNeue;" class="">URL-escaped, thus already</span><span style="font-family: HelveticaNeue;" class=""> ASCII"</span></div><div class=""><br class=""></div><div class="">And those who see no value in such a runtime message — and thus likely also see no value such a comment — are free not to use either.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">Paul</div><div class=""><br class=""></div></div></div></body></html>