I was put off by the #"..."#
syntax at first, but I was completely turned around by the idea that this allows us to not add raw strings to the language as a different kind of string literal. We already have the difference between regular and multiline string literals, and I was prepared to have the full matrix of "single-line raw" and "multiline raw" literals. But this lets us avoid that. From the proposal:
String Start Delimiter Escape Delimiter String End Delimiter " |" #" \# "# ##" \## "## ######" \###### "######
I found this table extremely compelling. Swift has one kind of single-line string. You start with 0 or more pound signs to describe how escaping works within the string, then you write the string literal, than you close with the same number of pound signs to allow embedded quotes. There's no such thing as a "raw string", and that keeps the language a little simpler than if "string literals with one or more quotes" were different from "string literals with zero quotes".
Complexity aside, I also think it's good in general to allow escapes even in "raw"-ish contexts. With shell-style '…'
or C++-style r"…"
you always end up with some scenario where you need to break out after all, and then you either need to use multiple literals or go through and carefully escape everything. This wouldn't even have to be about interpolation or quote characters; it could just be a Unicode escape in a file that's supposed to stay ASCII-compatible for whatever reason.
I think #
is as good a sigil as we're going to get, and it matches #selector
, so I'm fine with that too. EDIT: I expect that the common case will be #"…"#
and that occasionally we'll dip to ##"…"##
or even ###"…"###
when talking about C preprocessor hacks, but that those last two will be so rare that it's not worth adding custom delimiter functionality.
(I also think whatever syntax we pick, we'll all get used to it in six months like we did with """
.)