SE-0200: Enhancing String Literals Delimiters to Support Raw Text

I'm in favor of this proposal; I've written enough code-gen in Swift recently that not having a raw string format is a frustrating experience of chasing the right number of backslashes. I'm also glad that raw strings support interpolation, since otherwise the feature would be a lot less useful.

Syntax-wise, the # sigil is much nicer than some of the heavier options that were discussed like @raw. However, looking back through one of the previous discussion threads, I even more strongly prefer @beccadax's suggestion of `"..."` (backtick-wrapped quotes) as a delimiter because it's even less visually noisy:

let foo = `"raw string"`
let bar = ``"raw string with `" inside it"``
let baz = `"here's an interpolation \`(foo)"`

Brent, since you're a coƤuthor on the proposal, is there a reason that the # was chosen over this one? I don't see it discussed in the proposal text beyond the general statement that backticks would clash with escaped identifiers, but as you point out in the previous thread, there shouldn't be a collision if they are immediately followed/preceded by double-quotes or other backticks.

If the intention is that you want raw strings to stand out more for easy identifiability than backtick-quote might perhaps allow, then that's a reasonable stance, but it would still be good to know if it was considered and have that reasoning noted somewhere.

That one preference aside, I'd also be happy with # as a delimiter if that's what we end up going with in the final implementation.

3 Likes