5 ms·
var v = """""" contents""""" """""" lol. I like the proposal to have these sort of raw strings, where indentations are removed, but can't they
by LandR 5y ago
var v = """"""
contents"""""
""""""
lol.
I like the proposal to have these sort of raw strings, where indentations are removed, but can't they use a symbol before the string like they do with interpolation `$` or literals `@`?
I know it says design decision to go with 1 more " than the longest sequence of " in the string, but why ?
- brandmeyer 5y agoI'm a fan of the C++ method. R"SQL(my string without the sequence S Q L goes here)SQL" You can use any extra delimiter you want. The concatenation rules make it easy for you to easily insert source code line breaks and indentation without literal string breaks or indentation.
- Metasyntactic 5y agoHi, I'm the lang designer here. We looked into this. However, there didn't seem to be any benefit to this above just the N-quote version (which fits into how C# does strings everywhere else). In the above case, the `SQL(` and `)SQL` tokens are just akin to N-quotes. Since there's no additional benefit, we went with the simpler approach that solves all these needs, but will look the same across all codebases.
- brandmeyer 5y agoConsistent use of language-specific tags makes it easier for tools to switch to a dedicated foreign-language parser when they encounter a tagged raw literal. The host language just provides the capability through arbitrary matchup, but its still up to users and tool authors to use them consistently. SQL is just one example. Embedded shader programs, XML (fragments), and Protobuf literals are other possibilities.
- GordonS 5y agoI'm in agreement: the function is needed, but the syntax feels really weird. I'd also much prefer some kind of prefix, maybe double "at", e.g. ``` var myString = @@"blah blah blah blah " ``` This feels a lot more natural to me.
- Someone 5y agoA design goal is that you won’t need to escape _any_ character sequence in the string. In your proposal, a " inside a literal string would have to be escaped. In practice, using """ will be sufficient almost all the time.
- fmorel 5y agoIt's more about not needing to escape characters than stripping indentation (that's just an extra perk). Otherwise, if the string can contain `"`, how can the compiler know which `"` defines the end of it?
- taco_emoji 5y agoThey literally explain why as design goal #1: > Provide a mechanism that will allow all string values to be provided by the user without the need for any escape-sequences whatsoever.
- mastax 5y agoRust uses any number of `#` e.g. ###"There can be "stuff without escapes" #" "# "### C# already uses @ for raw string prefixes so they could extend it's usage for multiple prefixes+suffixes. """ Is fine though.
- Metasyntactic 5y ago> but can't they use a symbol before the string like they do with interpolation `$` or literals `@`? Hi! I'm the language designer here :) I know it says design decision to go with 1 more " than the longest sequence of " in the string, but why ? Because if we use a symbol before the string, then there needs to be some mechanism to escape it within the string. e.g. if you use `@` literals, you still need to escape quotes within the string literal. The point of this feature (which we try to spell out in the spec) is so that you can have content without the need to escape anything at all.