<div dir="ltr"><div>To me the discussion about precision of multiline strings is missing the point. The biggest use case of this would be when using swift in a more script-like fashion. You just paste something, add a .components(separatedBy: “\n”).map { something() } and you print the result.</div><div><br></div><div>If you need precision, localizations, etc, multiline strings don’t have too much to offer. You could just use plain + with marginal overhead. Or use resource files.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 3, 2017 at 11:18 PM, Ricardo Parada via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Why would backslashes at the end of each line be a nice idea?<br><br>Sent from my iPhone</div><div><div class="h5"><div><br>On Apr 3, 2017, at 2:44 PM, Paweł Wojtkowiak via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><div>I think that there's nothing wrong with two "tools" for the same task in this case. Multiline strings look better in the code and are easier to read and can serve many purposes. By reading different texts from swift dev team I feel like this is something the language was designed with in mind. They're also easier to type and it needn't neccessarily be a string presented to the user. </div><div id="m_-6247164852014482344AppleMailSignature"><br></div><div id="m_-6247164852014482344AppleMailSignature">Lets say I want a simple json literal for testing purposes - reading from a file takes much more effort comparing to inserting it directly in the code. Taking out every new line character makes it hard to read, and inserting quotes and pluses every line both needs extra effort and also decreases readability. Adding it as a multiline string would make a perfect solution for this to me.</div><div id="m_-6247164852014482344AppleMailSignature"><br></div><div id="m_-6247164852014482344AppleMailSignature">There are so many other cases where this could be useful too. I like how python has the """ and I think this would be a good direction to go, although this is true that python uses indentation in a different way, so I think backslashes at the end of each line would be a nice idea - this is still better than concatenating each line with " and +, and would have the least readability impact. Also, it could be treated as a literal and be evaluated at compile time.</div><div><br></div><blockquote type="cite"><div><div dir="ltr">I just checked with -O and without and was surprised to find that `let x = "abc" + "def" + "ghi"` wasn't collapsed into a single string literal "abcdefghi" in the generated assembly code. Maybe it's more difficult than it is in some other languages because of operator overloads and different kinds of text literals (strings, extended grapheme clusters, Unicode scalars)?<div><br></div><div>Regardless of the reasons, a separate syntax isn't the right way to achieve this optimization—the compiler should just do it automatically. Like Ricardo, "multi-line string literals" should be reserved for string literals that include the newline characters that are used to break them up in source. The idea of supporting something like the Python example above just provides two ways to do the same thing, which I don't think we really need.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Apr 3, 2017 at 8:18 AM Ricardo Parada via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></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="m_-6247164852014482344gmail_msg"><div class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344gmail_msg"></div>I would think that the concatenation would get resolved at runtime, unless the compiler gets smart about it. But either way I do not see it as a problem. The reason is that I don't remember ever worrying about the performance of concatenating a few lines of text. :-)<div class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344gmail_msg"></div><div class="m_-6247164852014482344gmail_msg">Thanks</div></div><div style="word-wrap:break-word" class="m_-6247164852014482344gmail_msg"><div class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344gmail_msg"><div class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344gmail_msg"><div class="m_-6247164852014482344gmail_msg"><blockquote type="cite" class="m_-6247164852014482344gmail_msg"><div class="m_-6247164852014482344gmail_msg">On Apr 3, 2017, at 11:13 AM, Adrian Zubarev <<a href="mailto:adrian.zubarev@devandartist.com" class="m_-6247164852014482344gmail_msg" target="_blank">adrian.zubarev@devandartist.<wbr>com</a>> wrote:</div><br class="m_-6247164852014482344m_4981237499957014445Apple-interchange-newline m_-6247164852014482344gmail_msg"><div class="m_-6247164852014482344gmail_msg"><div class="m_-6247164852014482344m_4981237499957014445bloop_markdown m_-6247164852014482344gmail_msg" style="font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254)"><p style="margin:15px 0px" class="m_-6247164852014482344gmail_msg">To me a literal a single entity which is solved at compile time. The concatenation is however resolved at runtime if I’m not mistaken here (it might be optimized at compile time but I still would expect a function executed a couple of times at runtime).</p><p style="margin:15px 0px" class="m_-6247164852014482344gmail_msg">Please correct me if I’m wrong here.</p><div style="margin:15px 0px" class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344m_4981237499957014445webkit-block-placeholder m_-6247164852014482344gmail_msg"></div></div><div class="m_-6247164852014482344m_4981237499957014445bloop_original_html m_-6247164852014482344gmail_msg" style="font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254)"><div id="m_-6247164852014482344m_4981237499957014445bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;margin:0px" class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344gmail_msg"></div><br class="m_-6247164852014482344gmail_msg"><div id="m_-6247164852014482344m_4981237499957014445bloop_sign_1491232271296286208" class="m_-6247164852014482344m_4981237499957014445bloop_sign m_-6247164852014482344gmail_msg"><div style="font-family:helvetica,arial;font-size:13px" class="m_-6247164852014482344gmail_msg">-- <br class="m_-6247164852014482344gmail_msg">Adrian Zubarev<br class="m_-6247164852014482344gmail_msg">Sent with Airmail</div></div><br class="m_-6247164852014482344gmail_msg"><p class="m_-6247164852014482344m_4981237499957014445airmail_on m_-6247164852014482344gmail_msg" style="margin:15px 0px">Am 3. April 2017 um 17:10:36, Ricardo Parada (<a href="mailto:rparada@mac.com" style="color:rgb(65,131,196);background-color:inherit;text-decoration:none" class="m_-6247164852014482344gmail_msg" target="_blank">rparada@mac.com</a>) schrieb:</p><blockquote type="cite" class="m_-6247164852014482344m_4981237499957014445clean_bq m_-6247164852014482344gmail_msg" style="margin:15px 0px"><span style="margin-top:0px;margin-bottom:0px" class="m_-6247164852014482344gmail_msg"><div style="word-wrap:break-word" class="m_-6247164852014482344gmail_msg"><div class="m_-6247164852014482344gmail_msg"></div><div class="m_-6247164852014482344gmail_msg">How is that better than this?<div class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344gmail_msg"></div><div class="m_-6247164852014482344gmail_msg"><div class="m_-6247164852014482344m_4981237499957014445bloop_markdown m_-6247164852014482344gmail_msg" style="font-family:Helvetica,Arial;font-size:13px;background-color:rgb(254,254,254)"><pre style="margin:15px 0px;font-family:Menlo,Consolas,'Liberation Mono',Courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(204,204,204);overflow:auto;padding:4px 8px;word-break:normal;word-wrap:normal" class="m_-6247164852014482344gmail_msg"><code class="m_-6247164852014482344m_4981237499957014445python m_-6247164852014482344gmail_msg" style="font-family:Menlo,Consolas,'Liberation Mono',Courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:0px;margin:0px;padding:0px;word-break:normal;word-wrap:normal">template = "This is the first line.\n" +
"This is the second line.\n" +
"This is the third line."
</code></pre><div style="margin:15px 0px" class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344m_4981237499957014445webkit-block-placeholder m_-6247164852014482344gmail_msg"></div></div><div class="m_-6247164852014482344m_4981237499957014445bloop_original_html m_-6247164852014482344gmail_msg" style="font-family:Helvetica,Arial;font-size:13px;background-color:rgb(254,254,254)"></div><div class="m_-6247164852014482344gmail_msg"><blockquote type="cite" style="margin:15px 0px" class="m_-6247164852014482344gmail_msg"><div style="margin-top:0px" class="m_-6247164852014482344gmail_msg">On Apr 3, 2017, at 10:42 AM, Ricardo Parada via swift-evolution <<a href="mailto:swift-evolution@swift.org" style="color:rgb(65,131,196);background-color:inherit;text-decoration:none" class="m_-6247164852014482344gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_-6247164852014482344m_4981237499957014445Apple-interchange-newline m_-6247164852014482344gmail_msg"><div style="margin-bottom:0px" class="m_-6247164852014482344gmail_msg"><div style="word-wrap:break-word" class="m_-6247164852014482344gmail_msg">It look prettier without the \n<div class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344gmail_msg"></div><div class="m_-6247164852014482344gmail_msg">It's not laziness.</div><div class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344gmail_msg"></div><div class="m_-6247164852014482344gmail_msg">I want my code to look pretty.</div><div class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344gmail_msg"></div><div class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344gmail_msg"><div class="m_-6247164852014482344gmail_msg"><blockquote type="cite" style="margin:15px 0px" class="m_-6247164852014482344gmail_msg"><div style="margin-top:0px" class="m_-6247164852014482344gmail_msg">On Apr 3, 2017, at 10:40 AM, Adrian Zubarev <<a href="mailto:adrian.zubarev@devandartist.com" style="color:rgb(65,131,196);background-color:inherit;text-decoration:none" class="m_-6247164852014482344gmail_msg" target="_blank">adrian.zubarev@devandartist.<wbr>com</a>> wrote:</div><br class="m_-6247164852014482344m_4981237499957014445Apple-interchange-newline m_-6247164852014482344gmail_msg"><div style="margin-bottom:0px" class="m_-6247164852014482344gmail_msg"><div class="m_-6247164852014482344m_4981237499957014445bloop_markdown m_-6247164852014482344gmail_msg" style="font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254)"><p style="margin:15px 0px" class="m_-6247164852014482344gmail_msg">What I was trying to say is that by automatically adding a new line character does not provide any benefit except of being lazy to type<span class="m_-6247164852014482344m_4981237499957014445Apple-converted-space m_-6247164852014482344gmail_msg"> </span><code style="font-family:Menlo,Consolas,'Liberation Mono',Courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal" class="m_-6247164852014482344gmail_msg">\n</code>.</p><pre style="margin:15px 0px;font-family:Menlo,Consolas,'Liberation Mono',Courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(204,204,204);overflow:auto;padding:4px 8px;word-break:normal;word-wrap:normal" class="m_-6247164852014482344gmail_msg"><code class="m_-6247164852014482344m_4981237499957014445swift m_-6247164852014482344gmail_msg" style="font-family:Menlo,Consolas,'Liberation Mono',Courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:0px;margin:0px;padding:0px;word-break:normal;word-wrap:normal">// In your model this would be equivalent
let s1 = "\n\n\n"
let s2 = """
" // However in my model this is an empty string and should be banned
"
""" // That's also an empty string, but it that case it indicates the end of the multi lined string
</code></pre><p style="margin:15px 0px" class="m_-6247164852014482344gmail_msg">I dislike the tradeoff of precision for laziness.</p><div style="margin:15px 0px" class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344m_4981237499957014445webkit-block-placeholder m_-6247164852014482344gmail_msg"></div></div><div class="m_-6247164852014482344m_4981237499957014445bloop_original_html m_-6247164852014482344gmail_msg" style="font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254)"><div id="m_-6247164852014482344m_4981237499957014445bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;margin:0px" class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344gmail_msg"></div><br class="m_-6247164852014482344gmail_msg"><div id="m_-6247164852014482344m_4981237499957014445bloop_sign_1491230112191910912" class="m_-6247164852014482344m_4981237499957014445bloop_sign m_-6247164852014482344gmail_msg"><div style="font-family:helvetica,arial;font-size:13px" class="m_-6247164852014482344gmail_msg">-- <br class="m_-6247164852014482344gmail_msg">Adrian Zubarev<br class="m_-6247164852014482344gmail_msg">Sent with Airmail</div></div><br class="m_-6247164852014482344gmail_msg"><p class="m_-6247164852014482344m_4981237499957014445airmail_on m_-6247164852014482344gmail_msg" style="margin:15px 0px">Am 3. April 2017 um 16:29:44, Ricardo Parada (<a href="mailto:rparada@mac.com" style="color:rgb(65,131,196);background-color:inherit;text-decoration:none" class="m_-6247164852014482344gmail_msg" target="_blank">rparada@mac.com</a>) schrieb:</p><blockquote type="cite" class="m_-6247164852014482344m_4981237499957014445clean_bq m_-6247164852014482344gmail_msg" style="margin:15px 0px"><div style="margin-top:0px;margin-bottom:0px" class="m_-6247164852014482344gmail_msg"><div style="font-family:helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="m_-6247164852014482344gmail_msg"><span style="margin-top:0px;margin-bottom:0px" class="m_-6247164852014482344gmail_msg">By the way, the multi-line string should allow \n\n, or as many as you may want to throw in there. I don't see a problem with that.</span></div><span style="margin-top:0px;margin-bottom:0px" class="m_-6247164852014482344gmail_msg"><br class="m_-6247164852014482344m_4981237499957014445Apple-interchange-newline m_-6247164852014482344gmail_msg"></span></div></blockquote></div><div class="m_-6247164852014482344m_4981237499957014445bloop_markdown m_-6247164852014482344gmail_msg" style="font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254)"><br class="m_-6247164852014482344m_4981237499957014445Apple-interchange-newline m_-6247164852014482344gmail_msg"></div></div></blockquote></div><br class="m_-6247164852014482344gmail_msg"></div></div>______________________________<wbr>_________________<br class="m_-6247164852014482344gmail_msg">swift-evolution mailing list<br class="m_-6247164852014482344gmail_msg"><a href="mailto:swift-evolution@swift.org" style="color:rgb(65,131,196);background-color:inherit;text-decoration:none" class="m_-6247164852014482344gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="m_-6247164852014482344gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="m_-6247164852014482344gmail_msg" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br class="m_-6247164852014482344gmail_msg"></div></blockquote></div><br class="m_-6247164852014482344gmail_msg"></div></div></div></span></blockquote></div><div class="m_-6247164852014482344m_4981237499957014445bloop_markdown m_-6247164852014482344gmail_msg" style="font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254)"><br class="m_-6247164852014482344m_4981237499957014445Apple-interchange-newline m_-6247164852014482344gmail_msg"></div></div></blockquote></div><br class="m_-6247164852014482344gmail_msg"></div></div></div>______________________________<wbr>_________________<br class="m_-6247164852014482344gmail_msg">
swift-evolution mailing list<br class="m_-6247164852014482344gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="m_-6247164852014482344gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="m_-6247164852014482344gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="m_-6247164852014482344gmail_msg" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br class="m_-6247164852014482344gmail_msg">
</blockquote></div>
</div></blockquote></div></blockquote><blockquote type="cite"><div><span>______________________________<wbr>_________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a></span><br></div></blockquote></div></div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>