[swift-evolution] multi-line string literals.

Brent Royal-Gordon brent at architechies.com
Thu May 5 15:51:06 CDT 2016

> It had the idea that maybe the motivation behind continuation quotes is to make using multiline strings harder to use; in order to discourage their use at all.

Absolutely not, and frankly I resent the implication.

I'm looking at a space where (in my opinion) all existing designs are ugly and inelegant and trying to find something better. There are *reasons* Swift 2 doesn't allow newlines in quote marks; I'm trying to address them, not ignore them. There are nasty formatting problems; I'm trying to solve them, not tolerate them. There are significant context-sensitivity issues; I'm trying to fix them, not punt the problem to a syntax highlighter that is absent or incorrect in half of our tools.

Here's a piece of code-generating code I once wrote, ported to this prototype:


(The actual code generation starts on line 93.) 

And here's the same code in (beta-era) Swift 2:


I think the new version is an improvement over the old. I think I like it better than I would with `"""` or heredocs forcing things against the left margin. I think it's nice that I can look at any line—out of context, random access—and see which parts are string literals. I think if I want to add a doc comment to each of the constants it generates, I have to do a little awkward code shuffling, but the result is worth it:

	for statusLine in statusLines {
	    code +=  "    /// The HTTP \(statusLine.code) \(statusLine.message) status, used with `HTTPResponseType.status`.
	             "    \(statusLine.constant)

Overall, I find this code a lot more pleasant to read than it was in Swift 2, and somewhat more pleasant than it would be with `"""` or a heredoc. Maybe you don't agree; maybe you'd rather import some other language's warts. I understand—those warts come with convenience advantages, and you might prefer that convenience to the other things.

But at least have the basic respect for opposing viewpoints not to impugn my motives because you disagree with me or don't like what I suggest. That is just not nice.

Brent Royal-Gordon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160505/fa9c40b6/attachment.html>

More information about the swift-evolution mailing list