<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=""><br class=""><div><blockquote type="cite" class=""><div class=""><span style="font-family: HelveticaNeue; font-size: 12px; font-style: normal; font-variant: 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; float: none; display: inline !important;" class="">The reason I raise the question is that some languages have multiple quote styles (Perl 5 has something like 3 or 4 different string literal styles IIRC?) with different policies. One reason for this is to disable processing of escapes: if you’re using string literals to enter something that uses \ or “ frequently, it can be irritating and ugly to have a lot of<span class="Apple-converted-space"> </span></span><a href="smb://'s" style="font-family: HelveticaNeue; font-size: 12px; font-style: normal; font-variant: 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="">\\'s</a><span style="font-family: HelveticaNeue; font-size: 12px; font-style: normal; font-variant: 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; float: none; display: inline !important;" class=""><span class="Apple-converted-space"> </span><</span><a href="smb://'s" style="font-family: HelveticaNeue; font-size: 12px; font-style: normal; font-variant: 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="">smb://'s</a><span style="font-family: HelveticaNeue; font-size: 12px; font-style: normal; font-variant: 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; float: none; display: inline !important;" class="">>. In some dialects of inline assembly in C, for example, this can lead to very ugly code.</span><br style="font-family: HelveticaNeue; font-size: 12px; font-style: normal; font-variant: 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=""><br style="font-family: HelveticaNeue; font-size: 12px; font-style: normal; font-variant: 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=""><span style="font-family: HelveticaNeue; font-size: 12px; font-style: normal; font-variant: 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; float: none; display: inline !important;" class="">When introducing a feature like this, I think it would be useful to survey a range of popular languages (and yes, even perl ;-) to understand what facilities they provide and why (i.e. what problems they are solving) and synthesize a good swift design that can solve the same problems with a hopefully simple approach.</span></div></blockquote></div><br class=""><div class="">While I think surveying the literature for inspiration is good, it is even better to look at motivating usecases. “multi-line string literals” is a feature everybody can get behind, but I wonder if there is agreement on the motivation.</div><div class=""><br class=""></div><div class="">For <b class="">me</b>, the motivation is that I am pasting the string from some external source. Suppose I’m writing JSON parsing code, and I paste `let json = <JSON>" at the top of the playground to test with. </div><div class=""><br class=""></div><div class=""><div class=""></div><blockquote type="cite" class=""><div class="">I would want multi-line string literals to behave as much like normal</div><div class="">string literals as possible for consistency. To optimize for developer</div><div class="">happiness, to steal the ruby saying, unexpected behavior should be kept to</div><div class="">a minimum. If \n works in a normal string literal, it should work in a</div><div class="">multi-line string literal... even if you could just hit enter instead.</div></blockquote></div><div class=""><br class=""></div><div class="">Well… the principle of least surprise depends entirely on what surprises you. If you start with a one-line string and then say “nevermind, two lines” then having the escape behavior change out from under you is surprising. On the other hand, if you are pasting long text from an external source, opting *into* escaping behavior is surprising.</div><div class=""><br class=""></div><div class="">The triple-quote proposal at least avoids the issue of accidentally prematurely terminating a pasted string in a lot of common cases. (JSON strings, for example.) However that is almost worse in some sense, as the other escape sequences are much more subtle than a compile error, and likely to slip past developer notice.</div><div class=""><br class=""></div><div class="">tl;dr: I have two questions.</div><div class=""><br class=""></div><div class="">1. Are multi-line strings more commonly used as “long single-line strings” (e.g. wants to be escaped) or “pasted data” (e.g. wants to be non-escaped)? How can we find out?</div><div class="">2. For what answers of 1 is it sensible to make the user ALWAYS be explicit about what behavior they want?</div></body></html>