3 ms·
Oh yeah, I was just sharing my string literal syntax that's been baking in my head for while for the sake of discussing. But off the top of my head, mainly jus
by __ryan__ 5y ago
Oh yeah, I was just sharing my string literal syntax that's been baking in my head for while for the sake of discussing.
But off the top of my head, mainly just that there's a clear visual indicator of the start of lines of text, rather than counting/lining up leading whitespace. In the first example, the strings are all tabbed evenly for the sake of looking "pretty" in the code, but the following would generate the same string, since each line begins after the """:
var xml = """<element attr="content">
""" <body>
""" </body>
"""</element>
""";
- Metasyntactic 5y agoHi. I'm the language designer behind this feature :) A few points. > but the following would generate the same string, since each line begins after the """: That's not a virtue here. The point is to be able to write clear literals that never need escapes and which allow for easy grokking of what the content actually is. All current string forms in C# require some amount of manual (or tooling) help to fix them up to be legal. That's not the case with this literal. The content can always work as-is without having to touch it at all.
- __ryan__ 5y agoThat definitely makes sense. In my (limited, especially not C#) experience I just really dislike reasoning about trimming the leading whitespace, even if the rules are simple. I yearn for a consistent visual cue. In my syntax, the IDE would ideally treat the """ block virtually like a <textarea>.
- Metasyntactic 5y ago> I just really dislike reasoning about trimming the leading whitespace Note: this feature is entirely optional. You can absolutely not have leading whitespace trimming at all. Indeed, this is a requirement of the proposal as we have to make it possible to actually represent text that has leading whitespace :)