[swift-evolution] [Accepted] SE-0168: Multi-Line String Literals
rltbennett at icloud.com
Fri Apr 21 08:48:36 CDT 2017
Xiaodi, I think one thing you're neglecting is that users may never print out a multiline literal string at all. A string might never be printed or read by a human outside of the code it resides in. In this case it seems perfectly reasonable to ask that it be possible to format the string nicely in the code and disregard how it would actually be printed.
Even if we intended to print every string we used, I don't agree that a string's representation in code should be coupled to its appearance when printed. That seems like a needless restriction to impose on the language. The whole point of multiline strings is to be able to visually lay out strings as desired, independent of the editor. Allowing manual line breaks without introducing a newline is one more step toward completing this goal.
To respond to your specific question as to why soft wrap is insufficient: it either looks bad because the wrapped text is unindented, or it introduces ambiguity by indenting the wrapped text (is that a wrapped line or two separate lines?). As Adrian Zubarev pointed out, we wouldn't need multiline string literals at all if we were content with manually inserting "\n" in multline strings and living with the soft wrapping. Evidently we are not content with that, so neither should we be content with having no way to break up long lines containing no newline character.
Finally, I see no reason why we should be fighting against this. It only makes multiline strings more capable. If you don't want to use manual wrapping of lines, you don't have to.
More information about the swift-evolution