5 ms·
I hope it will also normalize newlines to `\n`. The current version of raw literals (@"...") just puts there whatever is in the file, so it in practice depends
by exyi 5y ago
I hope it will also normalize newlines to `\n`. The current version of raw literals (@"...") just puts there whatever is in the file, so it in practice depends on if your program was compiled on Windows or Linux. Surely that should be irrelevant for the compilation to intermediate language
- gpderetta 5y agoSurely it depends on the encoding of the source, not where it was compiled?
- rawling 5y agoI think you're right: > Any line breaks within verbatim string literals are part of the resulting string. If the exact characters used to form line breaks are semantically relevant to an application, any tools that translate line breaks in source code to different formats (between "\n" and "\r\n", for example) will change application behavior. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...
- exyi 5y agoYes it does, but usually \n is committed in git, but on Windows it checks out as \r\n. So you are right that it technically does not depend on the system, but in practice there is a difference.
- gpderetta 5y agoThat's a very good point. Is it best practice to configure git to change line endings on Windows? I understand that these days Windows editors can handle unix line terminators corerctly.
- GoblinSlayer 5y agoAt least in visual studio this seems to be default and there's no way to change it.
- gpderetta 5y agoApparently it is possible, it is just very well hidden: https://stackoverflow.com/questions/3802406/configure-visual-studio-to-use-unix-line-endings https://stackoverflow.com/questions/3802406/configure-visual...
- GoblinSlayer 5y agoI mean git setting, not the text editor setting. Git checks out all files in CRLF format irrespective of your text editor.
- Metasyntactic 5y agoHi, i'm the lang designer and implementor here. We absolutely do not normalize newlines as that would defeat the purpose of raw literals. The point here is that your content is not interpreted as that's the pain area that people are hitting today. How you write your literal is what you get at the end of the day. Note: if the content needs to be `\n` then just use that actual newline in teh code. WRT to the file line endings and whatnot, my recommendation is that you never use tools that arbitrarily change that behind your back as it does already have impact today in C#. For example, that will break standard `@""` strings today. If your line endings are important, then your tools should be setup to respect what you wrote and not change them. All editors can be setup this way, as can git. And that would absolutely be my recommendation on how you should structure things for your code if newlines are relevant.
- jimmygrapes 5y agoAre you left handed by any chance? Trying to resolve an argument about typos in right and left handed people, and I've noticed you have wrote "teh" in many comments (no judgement, you're doing God's work in my opinion). My theory is left handed people are more likely to press e faster than the right hand can get to t and h (in qwerty).
- Measter 5y agoI've not kept up with C#, but does it have something akin to Rust's string continuation? In a Rust string literal a backslash followed by a newline causes the backslash and all following whitespace to be removed. So, for example: let string = "foo\ bar"; Results in `string` having the contents "foobar". That would allow the user to specify the exact newline they need without depending on invisible characters remaining unchanged.