<div dir="ltr">On Tue, May 16, 2017 at 4:01 PM, David Hart <span dir="ltr">&lt;<a href="mailto:david@hartbit.com" target="_blank">david@hartbit.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span><blockquote type="cite"><div>On 16 May 2017, at 17:36, Gwendal Roué &lt;<a href="mailto:gwendal.roue@gmail.com" target="_blank">gwendal.roue@gmail.com</a>&gt; wrote:</div><br class="m_-7735951194475909038m_-1807125886674018560Apple-interchange-newline"><div><div style="word-wrap:break-word"><br><blockquote type="cite">Le 16 mai 2017 à 16:39, David Hart &lt;<a href="mailto:david@hartbit.com" target="_blank">david@hartbit.com</a>&gt; a écrit :<br><br><blockquote type="cite"><br>On 16 May 2017, at 15:01, Gwendal Roué &lt;<a href="mailto:gwendal.roue@gmail.com" target="_blank">gwendal.roue@gmail.com</a>&gt; wrote:<br><br>Xiaodi Wu, your opposition has been recorded. You don&#39;t buy the Motivation section. Other people here do, definitely.<br><br><blockquote type="cite">Divorce the &quot;&quot;&quot; delimiter from the multi-line syntax and have them only support unescaped double-quotes<br></blockquote><br>This means support for:<br><br><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span>let x = &quot;<br><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span>foo<br><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span>bar<br><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span>&quot;<br><br>This one is unexpected, and not requested by many users. Does it bring much?<br><br>I wonder whether this addition was introduced in order to make the proposal as consistent as possible, and prevent some criticisms. It has proven pointless. I suggest forgetting about pleasing people who don&#39;t want to be pleased, and to reconsider this &quot;divorce&quot; section. Consistency is not the main point. The main point is UX. This means easing the daily life of code writers, and easing the daily life of code readers (this involves being careful which text editors and code prettyfiers are unable to handle the proposal).<br></blockquote><br>Well, one of the issues I have with the status-quo is that &quot;&quot;” has two meanings (support for “ without escaping and multi-line support), which causes consistency issues when you want to support “&quot;” one-liners. I prefer a model where features can be orthogonally composed: hence “”” for escaping, and newlines around delimiters to signify multi-lines. Support for multi-lines with “ delimiters is a natural consequence of that model: so why disallow it?<br></blockquote><br>Because this pollutes your proposal. Instead of making it simpler, it makes it more complex. You force the reader to think about the consequences of the composition of orthogonal topics, and sort between useful ones that improve life, and useless ones that pollute the mind, the time of stack overflow reviewers, and the future Swift String tutorials. Do you want to give more work to the linters and style fashionistas who love those kind of holes in language?<br></div></div></blockquote><div><br></div></span><div>If my proposal was accepted as-is except “ multi-line delimiters were disallowed, I would find that rather inelegant. That’s why I’m mentioning it. I prefer the proposal to be a bit more “polluted” but be more detailed.</div><br><blockquote type="cite"><div><div style="word-wrap:break-word"><span>If the two following literals are equivalent, I suggest your forget about the first, since it brings nothing on top of SE-0168:<br><br>&quot;<br><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span>foo<br><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span>bar<br>&quot;<br><br>&quot;&quot;&quot;<br><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span>foo<br><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span>bar<br></span>“&quot;&quot;<br></div></div></blockquote><div><br></div><div>I don’t understand the argument. As per my proposal, the following two strings are also equivalent:</div><div><br></div><div>“foo bar”</div><div>“””foo bar”””</div><div><br></div><div>The second simply allows the use of double-quote heavy strings with not escaping at the expense of longer delimiters. Why couldn’t that argument also be made for the examples you gave above?</div><div><br></div><div>Anyway, it’s probably not worth spending too much time discussing details like this. Let’s agree on the important stuff first :)</div><div><div class="m_-7735951194475909038h5"><br><blockquote type="cite"><div><div style="word-wrap:break-word">The proposal argument for it is weak:<br><br><blockquote type="cite">They gain support for &quot; delimiters, which has the nice advantage of saving a few characters in multi-line strings which are known to never contain double-quotes:<br></blockquote><br>&quot;never&quot; is a smelly word: real programs evolve, and good diffs are local diffs:<br><br> // bad diff<br>- &quot;<br>+ &quot;&quot;&quot;<br>...<br>...<br>...<br>- “Yes”, he said.<br>+ &quot;Yes&quot;, he said<br>...<br>...<br>...<br>-&quot;<br>+&quot;&quot;&quot;<br><br><blockquote type="cite">Support escaping newlines in multi-line strings with a trailing \<br><blockquote type="cite"><br>Great. That&#39;s the main request, unless I&#39;m misled: split long literals accross multiple lines. <br><br>Now that Xiaodi Wu has found them, the core team questions about the trailing backslash should be addressed in more details.<br></blockquote><br>Sure:<br></blockquote><br>Cool. Hard-wrapping is the meat.<br><br><blockquote type="cite">acknowledge[] that single-line triple quoted strings have other uses in other languages, [...] but supporting that alongside the indentation-stripping behavior leads to a lot of subtlety, and there could be other solutions to the escaping problem down the line, such as raw strings.<br><br>I’m not sure what subtleties they are referring to, so I don’t know how to address those fears. And I’m not convinced raw strings are the right solution because I’d like to retain escaping and string interpolation even in those one-liners. Raw strings are interesting, I just don’t see them as a solution for triple-quoted one-liners.<br></blockquote><br>This is about &quot;single-line triple quoted strings&quot;, not trailing backslash and hard-wrapping. Still, more about that below, in the section about C inspiration.<br><br><blockquote type="cite"><br>[d]iscussion on the list raised the idea of allowing a line to end with \ to &quot;escape&quot; the newline and elide it from the value of the literal.&#39; They deliberately rejected that feature for Swift 4, reasoning that &#39;[they] had concerns about only allowing that inside multi-line literals and felt that that could also be considered later as an additive feature.<br><br>This last one confused me. In what else than multi-line literals could we escape newlines? Be definition, if you don’t escape it, it’s a newline and your are by definition in a multi-line literal.<br></blockquote><br>This means that SE-0168 was about triple-quoted literals, and that the core team felt uneasy supporting trailing backslash for triple-quoted literals only.<br><br>If you intend to provide hard-wrapping with the trailing backslash, your proposal must support it in single-quoted literals also.<br></div></div></blockquote><div><br></div></div></div><div>At, let’s start with that. If support for trailing backslash in single-quoted literals is mandatory, I see three ways of handling it:</div><div><br></div><div><b>1. No special indentation stripping</b></div><div><b><br></b></div><div>print(“This is a \</div><div>single-line \</div><div>sentence”)</div><div><br></div><div><b>2. Strip indentation based on the last line (similar to “””)</b></div><div><br></div><div>print(“This is a \<br>    single-line \<br>    sentence”)</div><div><br></div><div><b>3. Line continuation style</b></div><div><br></div><div><div>print(“This is a \<br>    &quot;single-line \<br>    &quot;sentence”)</div><div><br></div><div><b>Opinion</b></div><div><br></div><div>The problem is that all of the above have their own issues IMHO (1 is not very useful, 2 is too similar to multi-lines so confusing, 3 is Adrian’s favorite but not an improvement over C-style concatenation). In fact, all of the above improves very little on C’s string literal concatenation:</div><div><br></div><div>print(“This is a &quot;<br>    &quot;single-line &quot;<br>    &quot;sentence”)</div><div><br></div><div>So by bother? Trailing backslash in single-quotes strings looks like “pollution” to me.</div></div></div></div></blockquote><div><br></div><div>Bingo. You&#39;ve just rephrased the core team&#39;s rationale for rejecting the `\` feature the first time round, and you&#39;ve also just demonstrated what Gwendal said earlier about focusing your proposal.</div><div><br></div><div>Your stated motivation is to improve hard-wrapping. The core team rejected `\` because it&#39;s a syntax for hard-wrapping that simply doesn&#39;t make sense for `&quot;` string literals. Their challenge for any would-be authors of future proposals on hard-wrapping is to create a single design that makes sense for both `&quot;&quot;&quot;` string literals and `&quot;` string literals. Instead, you are re-proposing `\` and also proposing a _different_ syntax, declaring that both features should be legal for both types of string literals; however, each syntax is still seriously lacking in ergonomics for one or the other type of string literal. This goes again to my original point: your proposal is re-stating a rejected feature.</div><div><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"><div><div><div>But if we need to have it, I’d go for the simplest possible solution (1).</div></div><span><br><blockquote type="cite"><div><div style="word-wrap:break-word"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Adopt the C/Objective-C syntax that concatenates single-line strings<br></blockquote><br>A battle-tested solution. Doesn&#39;t it look redundant with both the &quot;divorce&quot; and the trailing backslash?<br></blockquote><br>It may look redundant but I see them supporting two different purposes:<br><br><div><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span>• Multi-line strings allow editing and copy/pasting of long strings, containing newlines, without having to prefix each line with a delimiter (because it does it’s nice leading whitespace stripping): it’s great for DSLs like SQL where newlines help readability but has no effect on parsing. But it comes at the expense of vertical space.<br></div><div><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span>• The string concatenation syntax is great for shorter pieces of text where newlines should not be inserted by default and where vertical space is more conservative: greater for text messages.<br></div><br>If we did not have that feature, long text messages which need manual wrapping would look like:<br><br>assert(condition, “””<br><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span>This is my message but after some point I need to go to the \<br><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span>next line and I need to escape newlines on every line.<br><span style="white-space:pre-wrap" class="m_-7735951194475909038m_-1807125886674018560Apple-tab-span">        </span>“”&quot;<br></blockquote><br>C string concatenation is quite good for strings that are not wrapped (think markdown), while SE-0168 literals shine for strings that are already wrapped (think commits written by Linus):<br></div></div></blockquote><div><br></div></span><div>Agreed. But trailing backslash in SE-0168 literals is even better for strings that are not wrapped (IMHO):</div><div><br></div><div>“”&quot;</div><span><div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sed \<br>facilisis erat. Maecenas placerat nisi id lectus lacinia, a vehicula \<br>mauris consequat.<br><br>Donec quam arcu, venenatis a varius non, placerat a ligula. Proin eget \<br>libero quis lacus sodales convallis lacinia in eros. Nulla mollis dictum \<br>ligula, ut facilisis sapien sollicitudin in.</div></span><div>“””</div><div><br></div><div>Don’t you think? (Notice the lack of \n when newlines are wanted, and the lack of the line continuation)</div><div><div class="m_-7735951194475909038h5"><br><blockquote type="cite"><div><div style="word-wrap:break-word"><font color="#219900"><font>// Non-wrapped strings:</font><br></font><br><span style="color:rgb(255,72,0)">&quot;</span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sed <span style="color:rgb(255,72,0)">&quot;</span><br><span style="color:rgb(255,72,0)">&quot;</span>facilisis erat. Maecenas placerat nisi id lectus lacinia, a vehicula <span style="color:rgb(255,72,0)">&quot;</span><br><span style="color:rgb(255,72,0)">&quot;</span>mauris consequat.<span style="color:rgb(255,72,0)">\n&quot;</span><br><span style="color:rgb(255,72,0)">&quot;</span><span style="color:rgb(255,72,0)">\n</span><span style="color:rgb(255,72,0)">&quot;</span><br><span style="color:rgb(255,72,0)">&quot;</span>Donec quam arcu, venenatis a varius non, placerat a ligula. Proin eget <span style="color:rgb(255,72,0)">&quot;</span><br><span style="color:rgb(255,72,0)">&quot;</span>libero quis lacus sodales convallis lacinia in eros. Nulla mollis dictum <span style="color:rgb(255,72,0)">&quot;</span><br><span style="color:rgb(255,72,0)">&quot;</span>ligula, ut facilisis sapien sollicitudin in.<span style="color:rgb(255,72,0)">&quot;</span><br><br><br><span style="color:rgb(255,72,0)">&quot;</span><span style="color:rgb(255,72,0)">&quot;</span><span style="color:rgb(255,72,0)">&quot;</span><br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sed facilisis erat. Maecenas placerat nisi id lectus lacinia, a vehicula mauris consequat.<br><br>Donec quam arcu, venenatis a varius non, placerat a ligula. Proin eget libero quis lacus sodales convallis lacinia in eros. Nulla mollis dictum ligula, ut facilisis sapien sollicitudin in.<br><span style="color:rgb(255,72,0)">&quot;</span><span style="color:rgb(255,72,0)">&quot;</span><span style="color:rgb(255,72,0)">&quot;</span><br><br><font color="#219900"><font>// Wrapped strings:</font><br></font><br><font color="#ff4800">&quot;</font>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sed<span style="color:rgb(255,72,0)">\n</span><span style="color:rgb(255,72,0)">&quot;</span><br><span style="color:rgb(255,72,0)">&quot;</span>facilisis erat. Maecenas placerat nisi id lectus lacinia, a vehicula<span style="color:rgb(255,72,0)">\n</span><span style="color:rgb(255,72,0)">&quot;</span><br><span style="color:rgb(255,72,0)">&quot;</span>mauris consequat.<span style="color:rgb(255,72,0)">\n</span><span style="color:rgb(255,72,0)">&quot;</span><br><span style="color:rgb(255,72,0)">&quot;</span><span style="color:rgb(255,72,0)">\n</span><span style="color:rgb(255,72,0)">&quot;</span><br><span style="color:rgb(255,72,0)">&quot;</span>Donec quam arcu, venenatis a varius non, placerat a ligula. Proin eget<span style="color:rgb(255,72,0)">\n</span><span style="color:rgb(255,72,0)">&quot;</span><br><span style="color:rgb(255,72,0)">&quot;</span>libero quis lacus sodales convallis lacinia in eros. Nulla mollis dictum<span style="color:rgb(255,72,0)">\n</span><span style="color:rgb(255,72,0)">&quot;</span><br><span style="color:rgb(255,72,0)">&quot;</span>ligula, ut facilisis sapien sollicitudin in.<span style="color:rgb(255,72,0)">&quot;</span><br><br><br><span style="color:rgb(255,72,0)">&quot;</span><span style="color:rgb(255,72,0)">&quot;</span><span style="color:rgb(255,72,0)">&quot;</span><br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sed<br>facilisis erat. Maecenas placerat nisi id lectus lacinia, a vehicula<br>mauris consequat.<br><br>Donec quam arcu, venenatis a varius non, placerat a ligula. Proin eget<br>libero quis lacus sodales convallis lacinia in eros. Nulla mollis dictum<br>ligula, ut facilisis sapien sollicitudin in.<br><span style="color:rgb(255,72,0)">&quot;</span><span style="color:rgb(255,72,0)">&quot;</span><span style="color:rgb(255,72,0)">&quot;</span><br><br>NB: C string concatenation has nothing to do with C&#39;s trailing backslash:<br><br>char *s = &quot;Long strings can be bro\  <br>ken into two or more pieces.&quot;;<br><br>The C&#39;s trailing backslash only means &quot;dear parser, please pretend the following newline does not exist.&quot; C has thus no support for indentation, unlike Swift and SE-0168. Since the core team has rejected triple-quoted strings that do not start with a newline because of subtleties with indentation, the proposal needs *great care* on this topic :-)<br><br><blockquote type="cite">Le 16 mai 2017 à 16:58, Tony Allevato &lt;<a href="mailto:tony.allevato@gmail.com" target="_blank">tony.allevato@gmail.com</a>&gt; a écrit :<br><br>Regarding the C/Objective-C syntax, what would be the advantages over concatenating the strings with `+`?<br></blockquote><br>The support for ExpressibleByStringLiteral and ExpressibleByStringInterpolati<wbr>on protocols.<br><br>Gwendal<br><br></div></div></blockquote></div></div></div><br></div></blockquote></div><br></div></div>