It’s rather cumbersome to write a single quote character in an interpolation. That’s annoying. This proposal fixes that.
Why use $ as an escape character?
Because that’s the only character that’s significant to the parse of an interpolation. Since the " normally terminates the parse, but “normal” escapes get processed by the interpolator rather than the parser, only $ usually influences the initial parse.
In addition, this can’t break anyone’s code, since $" in an interpolation right now is a parse error.
Why not use \ as an escape character?
Because the interpolator is responsible for processing escapes, it would be inconsistent for the parser to process the \ only as an escape for a preceding ". Various proposals around this have made the rounds, and it has been found very controversial at least. The implementation also seems somewhat hairy.
Could this be part of something more ambitious?
Yes. I don’t have that ambition though. Of all the proposals around interpolations and escapes I’ve read so far, this proposal breaks none of them.
While I don’t want to suggest that the size of a diff is indicative if the importance of a change, or that small changes can’t have far-reaching impact, I want to stress that the actual implementation of this change is 2 lines of code changed. Not long ones either.
Thanks Martijn for this suggestion I like the idea, I always get escape characters wrong and I don’t like using triple quotes to fix this kind of issues. Let’s see what the Community thinks, and then we can proceed with a SIP + an official discussion in one of our SIP meetings.
The other quote? In any case, either the typo or my inability to read small font demonstrates the problem, that escaped quote should be easy to write and read. Arguably, even backslash quote isn’t obvious, even if it were supported.
First, that inserts a ' single quote, not a " double quote. Second, while it is not much of a problem in a monospace font, ${'"'}, ${’"’} is hard to decipher without leaning in and thus intrrupting the normal reading of it all.
And thirdly, $" would be a simple rule to learn but be concise and unambiguous. ${'"'} brings in the expanded format of $, uses a character in a string environment which may be confusing (and using ${"\""} may relieve that but then you’re thinking “I’m inserting a string with an escaped quote because I cannot just escape the quote normally?”), and ultimately also adds a small overhead in that now the string array passed to the interpolator is one entry longer and one more run-time insertion is needed.
At least, that’d be my gripes with favoring $" over it.
Hey Martijn, I think this merits a proposal and the branch you linked LGTM I’m on vacation but I will get back to your proposal as soon as I’m back (by the way, I commented on the commit of your PR several suggestions).