<div dir="ltr">On Wed, Apr 12, 2017 at 5:20 PM, Brent Royal-Gordon <span dir="ltr"><<a href="mailto:brent@architechies.com" target="_blank">brent@architechies.com</a>></span> wrote:<br><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-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div>Wow, maybe I shouldn't have slept.</div><div><br></div><div>Okay, let's deal with trailing newline first. I'm *very* confident that trailing newlines should be kept by default. This opinion comes from lots of practical experience with multiline string features in other languages. In practice, if you're generating files in a line-oriented way, you're usually generating them a line at a time. It's pretty rare that you want to generate half a line and then add more to it in another statement; it's more likely you'll interpolate the data. I'm not saying it doesn't happen, of course, but it happens a lot less often than you would think just sitting by the fire, drinking whiskey and musing over strings.</div><div><br></div><div>I know that, if you're pushing for this feature, it's not satisfying to have the answer be "trust me, it's not what you want". But trust me, it's not what you want.</div></div></blockquote><div><br></div><div>This is not a very good argument. If you are generating files in a line-oriented way, it is the function _emitting_ the string that handles the line-orientedness, not the string itself. That is the example set by `print()`:</div><div><br></div><div>```</div><div>print("Hello, world!") // Emits "Hello, world!\n"</div><div>```</div><div><br></div><div>Once upon a time, if I recall, this function was called `println`, but it was renamed. This particular example demonstrates why keeping trailing newlines by default is misguided:</div><div><br></div><div>```</div><div>print(</div><div> """</div><div> Hello, world!</div><div> """</div><div>)</div><div>```</div><div><br></div><div>Under your proposed rules, this emits "Hello, world!\n\n". It is almost certainly not what you want. Instead, it is a misguided attempt by the designers of multiline string syntax to do the job that the designers of `print()` have already accounted for.</div><div><br></div><div>If we were to buy your line of reasoning and adapt it for single-line strings, we would arrive at a rather absurd result. If you're emitting multiple single-line strings, you almost certainly want a space to separate them. Again this is exemplified by the behavior of `print()`:</div><div><br></div><div>```</div><div>print("Hello", "Brent!")</div><div>```</div><div><br></div><div>This emits "Hello Brent!" (and not "HelloBrent!"). But we do not take that reasoning and demand that "This is my string" end with an default trailing space, nor do we have `+` concatenate strings by default with a separating space.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div>Moving to the other end, I think we could do a leading newline strip *if* we're willing to create multiline and non-multiline modes—that is, newlines are _not allowed at all_ unless the opening delimiter ends its line and the closing delimiter starts its line (modulo indentation). But I'm reluctant to do that because, well, it's weird and complicated. I also get the feeling that, if there's a single-line mode and a multi-line mode, we ought to treat them as truly orthogonal features and allow `"`-delimited strings to use multi-line mode, but I'm really not convinced that's a good idea.</div><div><br></div><div>(Note, by the way, that heredocs—a *really* common multiline string design—always strip the leading newline but not the trailing one.)</div><div><br></div><div>Adrian cited this example, where I agree that you really don't want the string to be on the same line as the leading delimiter:</div><div><br></div><div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">        </span>let myReallyLongXMLConstantName = """<?xml version="1.0"?></div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">        </span> <catalog></div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">        </span> <book id="bk101" empty=""></div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">        </span> <author>John Doe</author></div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">        </span> <title>XML Developer's Guide</title></div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">        </span> <genre>Computer</genre></div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">        </span> <price>44.95</price></div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">        </span> </book></div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">        </span> </catalog>\</div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">        </span> """ </div><br class="gmail-m_-4413069624854317166Apple-interchange-newline">But there are lots of places where it works fine. Is there a good reason to force an additional newline in this?</div><div><br></div><div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">                        </span>case .isExprSameType(let from, let to):</div></div><div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">                                </span>return """checking a value with optional type \(from) against dynamic type \(to) \</div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">                                        </span> succeeds whenever the value is non-'nil'; did you mean to use '!= nil'?\</div><div><span class="gmail-m_-4413069624854317166Apple-tab-span" style="white-space:pre-wrap">                                        </span> """</div></div><div><br></div><div>I mean, we certainly could, but I'm not convinced we should. At least, not yet.</div><div><br></div><div>In any case, trailing newline definitely stays. Leading newline, I'm still thinking about.</div><div><br></div><div>As for other things:</div><div><br></div><div>* I see zero reason to fiddle with trailing whitespace. If it's there, it might be significant or it might not be. If we strip it by default and we shouldn't, the developer has no way to protect it. Let's trust the developer. (And their tooling—Xcode, I believe Git, and most linters already have trailing whitespace features. We don't need them too.)</div><div><br></div><div>* Somebody asked about `"""`-delimited heredocs. I think it's a pretty syntax, but it's not compatible with single-line use of `"""`, and I think that's probably more important. We can always add heredocs in another way if we decide we want them. (I think `#to(END)` is another very Swifty syntax we could use for heredocs--less lightweight, but it gives us a Google-able keyword.)</div><div><br></div><div>* Literal spaces and tabs cannot be backslashed. This is really important because, if you see a backslash after the last visible character in a line, you can't tell just by looking whether the next character is a space, tab, or newline. So the solution is, if it's not a newline, it's not valid at all.</div><div><br></div><div>I'll respond to Jarod separately.</div><br><div><blockquote type="cite"><div>On Apr 12, 2017, at 12:07 PM, John Holdsworth <<a href="mailto:mac@johnholdsworth.com" target="_blank">mac@johnholdsworth.com</a>> wrote:</div><br class="gmail-m_-4413069624854317166Apple-interchange-newline"><div><div style="word-wrap:break-word"><div>Finally.. a <a href="http://johnholdsworth.com/swift-LOCAL-2017-04-12-a-osx.tar.gz" target="_blank">new Xcode toolchain</a> is available largely in sync with the proposal as is.</div><div>(You need to restart Xcode after selecting the toolchain to restart SourceKit)</div><div><br></div><div>I personally am undecided whether to remove the first line if it is empty. The new</div><div>rules are more consistent but somehow less practical. A blank initial line is almost</div><div>never what a user would want and I would tend towards removing it automatically.</div><div>This is almost what a user would it expect it to do.</div><div><br></div><div>I’m less sure the same applies to the trailing newline. If this is a syntax for</div><div>multi-line strings, I'd argue that they should normally be complete lines -</div><div>particularly since the final newline can so easily be escaped.</div><span class="gmail-"><div><br></div><div><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures"> </span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures"> longstring = ""</span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">"\</span></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures"> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod \</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures"> tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, \</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures"> quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures"> "</span><span style="font-variant-ligatures:no-common-ligatures">""</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">print</span><span style="font-variant-ligatures:no-common-ligatures">( ""</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">"\</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures"> Usage: myapp <options></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"> </span><br class="gmail-m_-4413069624854317166webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures"> Run myapp to do mything</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"> </span><br class="gmail-m_-4413069624854317166webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures"> Options:</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures"> -myoption - an option</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures"> "</span><span style="font-variant-ligatures:no-common-ligatures">"" )</span></div></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div></span><div>(An explicit “\n" in the string should never be stripped btw)</div><div><br></div><div>Can we have a straw poll for the three alternatives:</div><span class="gmail-"><div><br></div><div>1) Proposal as it stands - no magic removal of leading/training blank lines.</div><div>2) Removal of a leading blank line when indent stripping is being applied.</div><div>3) Removal of leading blank line and trailing newline when indent stripping is being applied.</div><div><br></div></span><div>My vote is for the pragmatic path: 2)</div><div><br></div><div>(The main intent of this revision was actually removing the link between how the</div><div>string started and whether indent stripping was applied which was unnecessary.)</div><br><div><blockquote type="cite"><div>On 12 Apr 2017, at 17:48, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="gmail-m_-4413069624854317166Apple-interchange-newline"><div><span style="font-family:helvetica;font-size:12px;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;float:none;display:inline">Agree. I prefer the new rules over the old, but considering common use cases, stripping the leading and trailing newline makes for a more pleasant experience than not stripping either of them.</span><br style="font-family:helvetica;font-size:12px;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"><br style="font-family:helvetica;font-size:12px;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"><span style="font-family:helvetica;font-size:12px;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;float:none;display:inline">I think that is generally worth prioritizing over a simpler algorithm or even accommodating more styles. Moreover, a user who wants a trailing or leading newline merely types an extra one if there is newline stripping, so no use cases are made difficult, only a very common one is made more ergonomic.</span></div></blockquote></div><br></div></div></blockquote></div><span class="gmail-HOEnZb"><font color="#888888"><br><div>
<span class="gmail-m_-4413069624854317166Apple-style-span" style="border-collapse:separate;font-variant-ligatures:normal;font-variant-east-asian:normal;line-height:normal"><div><div style="font-size:12px">-- </div><div style="font-size:12px">Brent Royal-Gordon</div><div style="font-size:12px">Architechies</div></div></span>
</div>
<br></font></span></div></blockquote></div><br></div></div>