<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=""><div>Hi everyone, this is my first post to swift-evolution, so I apologize in advance if I violate any rules of list etiquette, and thanks for reading!</div><div><br class=""><blockquote type="cite" class=""><div class="">On Jun 18, 2016, at 17:44, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">On Sat, Jun 18, 2016 at 4:50 PM, Michael Peternell via swift-evolution<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><span class=""><br class="">&gt; Am 17.06.2016 um 07:45 schrieb Charlie Monroe via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:<br class="">&gt;<br class="">&gt; Motivational example:<br class="">&gt;<br class="">&gt; var urlString = self.urlString<br class="">&gt; if urlString.hasPrefix("//") {<br class="">&gt;&nbsp; &nbsp; &nbsp; &nbsp;urlString = "http:" + urlString // urlString needs to be typed twice<br class="">&gt; }<br class="">&gt;<br class="">&gt; While there is currently an easy way to append string using +=, there is no shortcut for prefixing a string. What I propose is adding a =+ operator for prefixing the string:<br class="">&gt;<br class="">&gt; urlString =+ "http:"<br class="">&gt;<br class="">&gt; Would anyone else find it useful?<br class=""><br class=""></span>No. What I would find useful though, is to recognize that addition is not string concatenation. There is a strong convention in mathematics that the "+" symbol should only be used for operations that are commutative. String concatenation is not commutative. (There are more conventions regarding "+", but all of them are respected by numbers, vectors, complex numbers, quaternions, or matrices - just to name a few.)<br class=""><br class="">I would like to have a different operator for string concatenation.</blockquote><div class=""><br class=""></div><div class="">I don't see how this would measurably improve Swift code. IIUC, much of the problem with `+` and strings arises from implicit conversions that don't happen in Swift. It's not even possible to write a generic algorithm that accidentally confuses arithmetic `+` and string concatenation `+`, since you would have to retroactively conform strings and numeric types to a nonsensical protocol of your own making.</div></div></div></div></div></blockquote><div><br class=""></div><div>I agree there’s no issue with type confusion, but I do agree with Michael that there’s a conceptual issue with using + for strings. I would certainly favor something that makes it more obvious visually that strings are the operands. An extreme example of where it might be a problem would be a construct like `"2" + "3"` (freely admitted to be a pathological case) - I’d have to look twice to recognize that the result was "23", not "5". My personal favorite for alternate string concat operators is Lua’s ".." syntax, though there are other options as well, especially in Swift. (Speaking for myself, I’d much rather be reminded of Lua than PHP’s single-dot or VB’s ampersand :).</div><div><br class=""></div><div>That having been said, the way things are now works and I don’t see the conceptual confusion being an immediate issue; if there are other arguments in favor of changing it, I’d speak out more strongly for it, but taking it as an entirely independent proposal, I'd wonder if it’s worth the break with previous versions in the near future.</div><div><br class=""></div><div>With respect to the original suggestion for an operator to prefix a string, I don’t see that as useful enough in the general case to warrant being in the stdlib (relative to how much authority I have to say anything about the stdlib at all! :), especially given that it’s very easy to write your own. I agree that writing a variable name twice is annoying, but given Swift’s predisposition towards let vs. var variables wherever possible, it shouldn’t be that common an issue in my (thus far somewhat limited) experience.</div><div><br class=""></div><blockquote type="cite" class=""><div dir="ltr" style="font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">Maybe "~~" or "++"? Now that the prefix and postfix operators for numbers ("++" and "--") are removed from Swift 3, "++" could be used for string concatenation.<br class=""><br class="">-Michael<br class=""></blockquote></div></div></div></blockquote></div><br class=""><div class=""><div>-- Gwynne Raskind</div><br class=""><blockquote type="cite" class=""><div dir="ltr" class="" style="font-family: Menlo-Regular;"><div class="gmail_extra"><div class="gmail_quote"></div></div></div></blockquote></div></body></html>