[swift-evolution] [Review] SE-0168: Multi-Line String Literals

Robert Bennett rltbennett at icloud.com
Thu Apr 6 21:59:15 CDT 2017


• What is your evaluation of the proposal?

-0.1

• Is the problem being addressed significant enough to warrant a change to Swift?

Yes

• Does this proposal fit well with the feel and direction of Swift?

I don't think so. While Python's way of doing multiline strings may work for Python, I don't think it's an aesthetic fit for Swift, both because of the somewhat nebulous treatment of newlines and the magical-feeling indentation. Magic is a core component of Python, but has no place in Swift.

The alternative, continuation quotes, is my preferred solution to this problem. However I think it would be improved if lines began with a single quote or pipe or some other character, basically anything other than double quotes.

Advantages of continuation characters are that it is immediately clear how much leading whitespace a line actually has and that the string's value is insensitive to the indentation of the individual lines. The second point will be very useful when copying and pasting multiline strings, as the value of the string cannot change unless whitespace is explicitly inserted after the leading character. How many times have we copy-pasted code in Python, only to be stung by improper indentation of the pasted code? With a leading character on continuation lines, you can highlight and auto-indent — that's the only kind of magic that Swift should support.

If we want to make copying and pasting text from elsewhere (e.g., SQL queries) simple, then the compiler can provide a fix-it for multiline strings lacking continuation characters, offering to place the continuation character at the start of each line at the position determined by the start of the least indented offending line.


However, if we decide not to go with continuation quotes, then I largely agree with what Haravikk said here: https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170403/035188.html


• If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

I don't like stealing from Python because Swift's and Python's styles are very different. Swift should steer clear of Python's magic.

Aside from Python, no.

• How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

A quick read, and followed the discussion.




More information about the swift-evolution mailing list