[swift-evolution] Thoughts on replacing \() with $() or some other symbol

Michael Peternell michael.peternell at gmx.at
Wed Jun 22 15:05:18 CDT 2016


> Am 22.06.2016 um 10:39 schrieb Goffredo Marocchi <panajev at gmail.com>:
> 
> Sorry, but can you explain why the character used to   escape   strings is also the best choice to do   Variable value extraction/String interpolation?  They are two different concepts.

They are two different concepts in the same way that salami pizza and pizza funghi are two different concepts.

The unifying concept (the "pizza") is this: A string starts with a `"`, has some letters, and ends with `"`; the letters in between the quotes are taken as-is, except for sequences starting with a `\`: `\n` is new line, ..., `\(...)` is string interpolation, ..., and finally you need to do `\\` to include a literal backslash into the string. So there is just one character (the backslash) which can start a special sequence. My opinion: `\` is rightfully the pizza character, not just the salami character.

Sorry for the cheesy analogy ;) In the end, it's just a matter of personal preference. Both approaches are equally sound on a theoretical level. To me, it was surprising at first, that `\` is used for string interpolation. But in a good way.

I think Swift 3 is heading in the right direction, and many changes provide real value. But there are also many things that should not change, like string interpolation syntax, "@noreturn" or removing the bridging of Objective-C types. Keeping the good things is just as important as inventing new stuff. Only a well-considered approach will bring major improvements.

-Michael



More information about the swift-evolution mailing list