C
C#β€’3mo ago
hutoanhill

βœ… whats up with this console output

Value
yellowThresholdWidth == 195.42857142857144
redThresholdWidth == 684
barWidth == 760
Value
yellowThresholdWidth == 195.42857142857144
redThresholdWidth == 684
barWidth == 760
Console.WriteLine($"Value " +
$"\nyellowThresholdWidth == {yellowThresholdWidth} " +
$"\nredThresholdWidth == {redThresholdWidth}" +
$"\nbarWidth == {barWidth}");
Console.WriteLine($"Value " +
$"\nyellowThresholdWidth == {yellowThresholdWidth} " +
$"\nredThresholdWidth == {redThresholdWidth}" +
$"\nbarWidth == {barWidth}");
93 Replies
hutoanhill
hutoanhillOPβ€’3mo ago
why is this adding so many tabs!? it makes no since. this is super simple but broken the new line somehow adds space chars equal to the number of chars before the line break smells like a bug
SG97
SG97β€’3mo ago
what do you mean?
No description
hutoanhill
hutoanhillOPβ€’3mo ago
No description
SG97
SG97β€’3mo ago
cannot reproduce that
hutoanhill
hutoanhillOPβ€’3mo ago
yea i am soo screwed
Omnissiah
Omnissiahβ€’3mo ago
is that rider? maybe there's a setting for newline
hutoanhill
hutoanhillOPβ€’3mo ago
possible. will check that out
cap5lut
cap5lutβ€’3mo ago
that looks a lot like that the console (the tab, not the class) expects a \r\n but Console.WriteLine() only writes a \n for some reason. \r = CR = Carriage Return, moves the cursor back to the line start (as in x = 0, if u will) \n = NL = New Line, move to the next line (as in y + 1, if u will) if u execute it from terminal/console outside of the IDE, does it work there as expected?
canton7
canton7β€’3mo ago
The "some reason" is that their string contains "\n" -- they're only calling Console.WriteLine once And seconded, this is exactly the output when you send "\n", but the terminal doesn't add an implicit "\r" with every "\n"
cap5lut
cap5lutβ€’3mo ago
oh right
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiXβ€’3mo ago
TeBeCo
REPL Result: Success
using System;

var yellowThresholdWidth = 1;
var redThresholdWidth = 2;
var barWidth = 3;

Console.WriteLine($"""
Value
yellowThresholdWidth == {yellowThresholdWidth}
redThresholdWidth == {redThresholdWidth}
barWidth == {barWidth}
""");
using System;

var yellowThresholdWidth = 1;
var redThresholdWidth = 2;
var barWidth = 3;

Console.WriteLine($"""
Value
yellowThresholdWidth == {yellowThresholdWidth}
redThresholdWidth == {redThresholdWidth}
barWidth == {barWidth}
""");
Console Output
Value
yellowThresholdWidth == 1
redThresholdWidth == 2
barWidth == 3
Value
yellowThresholdWidth == 1
redThresholdWidth == 2
barWidth == 3
Compile: 480.701ms | Execution: 30.757ms | React with ❌ to remove this embed.
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiXβ€’3mo ago
TeBeCo
REPL Result: Success
using System;

var yellowThresholdWidth = 1;
var redThresholdWidth = 2;
var barWidth = 3;

Console.WriteLine($"""
Value
yellowThresholdWidth == {yellowThresholdWidth}
redThresholdWidth == {redThresholdWidth}
barWidth == {barWidth}
""");
using System;

var yellowThresholdWidth = 1;
var redThresholdWidth = 2;
var barWidth = 3;

Console.WriteLine($"""
Value
yellowThresholdWidth == {yellowThresholdWidth}
redThresholdWidth == {redThresholdWidth}
barWidth == {barWidth}
""");
Console Output
Value
yellowThresholdWidth == 1
redThresholdWidth == 2
barWidth == 3
Value
yellowThresholdWidth == 1
redThresholdWidth == 2
barWidth == 3
Compile: 506.782ms | Execution: 30.704ms | React with ❌ to remove this embed.
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiXβ€’3mo ago
TeBeCo
REPL Result: Success
using System;

var yellowThresholdWidth = 1;
var redThresholdWidth = 2;
var barWidth = 3;

Console.WriteLine($"""
Value
yellowThresholdWidth == {yellowThresholdWidth}
redThresholdWidth == {redThresholdWidth}
barWidth == {barWidth}
""");
using System;

var yellowThresholdWidth = 1;
var redThresholdWidth = 2;
var barWidth = 3;

Console.WriteLine($"""
Value
yellowThresholdWidth == {yellowThresholdWidth}
redThresholdWidth == {redThresholdWidth}
barWidth == {barWidth}
""");
Console Output
Value
yellowThresholdWidth == 1
redThresholdWidth == 2
barWidth == 3
Value
yellowThresholdWidth == 1
redThresholdWidth == 2
barWidth == 3
Compile: 483.969ms | Execution: 30.941ms | React with ❌ to remove this embed.
cap5lut
cap5lutβ€’3mo ago
im cant find it, which line break does that multi line string literal use? the one from the source code, depends on how u compile or runtime dependent?
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
so there is no clear answer to that D:
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
seems easy to check
MODiX
MODiXβ€’3mo ago
cap5lut
sharplab.io (click here)
var yellowThresholdWidth = 1;
var redThresholdWidth = 2;
var barWidth = 3;
Console.WriteLine($"""
Value
yellowThresholdWidth == {yellowThresholdWidth}
redThresholdWidth == {redThresholdWidth}
barWidth == {barWidth}
""");
var yellowThresholdWidth = 1;
var redThresholdWidth = 2;
var barWidth = 3;
Console.WriteLine($"""
Value
yellowThresholdWidth == {yellowThresholdWidth}
redThresholdWidth == {redThresholdWidth}
barWidth == {barWidth}
""");
React with ❌ to remove this embed.
cap5lut
cap5lutβ€’3mo ago
the line break is included and encoded as CRLF in the string literal
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
defaultInterpolatedStringHandler.AppendLiteral("\r\nredThresholdWidth == "); there is encoded as CRLF, and i doubt any magic happens under the hood to normalize the literal. thus it seems more likely that its source dependent
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
oh sorry, should have mentioned that but it might not be true, i expected that sharplab runs on a linux container
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
but its windows Microsoft Windows NT 10.0.17763.0
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
but in the end it would still be compile time and not runtime so its either source dependent or compiler host platform dependent because its not using Environment.NewLine at all but the escape sequence
MODiX
MODiXβ€’3mo ago
TeBeCo
REPL Result: Failure
using System;
var s = $"""
a
b
""";

ReadOnlySpan<char> x = s.AsSpan();
foreach(var c in x)
{
Console.WriteLine((byte)c);
}
using System;
var s = $"""
a
b
""";

ReadOnlySpan<char> x = s.AsSpan();
foreach(var c in x)
{
Console.WriteLine((byte)c);
}
Exception: CompilationErrorException
- Field or auto-implemented property cannot be of type 'ReadOnlySpan<char>' unless it is an instance member of a ref struct.
- foreach statement cannot operate on enumerators of type 'ReadOnlySpan<char>.Enumerator' in async or iterator methods because 'ReadOnlySpan<char>.Enumerator' is a ref struct.
- Field or auto-implemented property cannot be of type 'ReadOnlySpan<char>' unless it is an instance member of a ref struct.
- foreach statement cannot operate on enumerators of type 'ReadOnlySpan<char>.Enumerator' in async or iterator methods because 'ReadOnlySpan<char>.Enumerator' is a ref struct.
Compile: 457.638ms | Execution: 0.000ms | React with ❌ to remove this embed.
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
modix is embedding that code weirldy
MODiX
MODiXβ€’3mo ago
cap5lut
REPL Result: Success
using System;
var s = $"""
a
b
""";

foreach(var c in s.ToCharArray())
{
Console.WriteLine((byte)c);
}
using System;
var s = $"""
a
b
""";

foreach(var c in s.ToCharArray())
{
Console.WriteLine((byte)c);
}
Console Output
97
10
98
97
10
98
Compile: 409.472ms | Execution: 35.986ms | React with ❌ to remove this embed.
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton7β€’3mo ago
Wat?
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiXβ€’3mo ago
cap5lut
REPL Result: Success
Environment.OSVersion
Environment.OSVersion
Result: OperatingSystem
{
"platform": 4,
"servicePack": "",
"version": "5.15.0.1059",
"versionString": "Unix 5.15.0.1059"
}
{
"platform": 4,
"servicePack": "",
"version": "5.15.0.1059",
"versionString": "Unix 5.15.0.1059"
}
Compile: 221.486ms | Execution: 18.618ms | React with ❌ to remove this embed.
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton7β€’3mo ago
What's OS dependent?
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
linebreak in multi line string literals
canton7
canton7β€’3mo ago
Doesn't it literally depend on whether your source file is saved with LF or CRLF?
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
not sure if discord normalizes the linebreaks somewhere tho
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
thats the question we have right now ;p
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton7β€’3mo ago
I'm pretty sure I read it an issue somewhere in dotnet/ a long time ago
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton7β€’3mo ago
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton7β€’3mo ago
IIRC there are unit tests in dotnet/runtime (or maybe /roslyn?) which are sensitive to the file line endings -- I saw that pop up recently
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton7β€’3mo ago
It was also raised in the proposal: https://github.com/dotnet/csharplang/issues/4304
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton7β€’3mo ago
Just tell git to checkout as LF? .gitattributes:
*.cs text eol=lf
*.cs text eol=lf
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton7β€’3mo ago
What? That line applies to all .cs files in your repo
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
for me its more the just-dont-use-raw-strings thingy here πŸ˜‚
canton7
canton7β€’3mo ago
Why not checkout .cs files as LF across the board?
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton7β€’3mo ago
You should have things set up so that they're stored in git as LF anyway
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton7β€’3mo ago
Yeah, if you specifically need CR in a particular string literal, that's a pain
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton7β€’3mo ago
But that's a pain in languages which don't rely on the file's line endings like Python, as well
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton7β€’3mo ago
Yeah, it wasn't clear that that's what you meant, because you speak in half-sentences πŸ˜‰
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
in ur local repo, even if u set it as EOL=LF, it wouldnt touch the source until u commit (or later) right? so if u locally work with an IDE that write CRLF everything works fine, all tests run fine and then after committing (and maybe more) it would explode? i .... think we should move this discussion out of this thread by now πŸ˜’
canton7
canton7β€’3mo ago
If they were previously CRLF, then you added that .gitattributes, you'd need git add --renormalize to change the actual files
cap5lut
cap5lutβ€’3mo ago
do IDEs read/analyze/respect these settings if u create a new cs file?
canton7
canton7β€’3mo ago
Not sure?
cap5lut
cap5lutβ€’3mo ago
and thats the problem ;p actually its not
canton7
canton7β€’3mo ago
It should get sorted the first time you git add maybe? Little fuzzy there
cap5lut
cap5lutβ€’3mo ago
u would add the .editorconfig thingy to the repo as well, wouldnt u?
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
i never ever touched these myself so im a virgin there πŸ˜‚
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton7β€’3mo ago
I've never had that not work
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
i think its also a bit about where that goes, nowadays a lot of terminals/text viewers/etc simply treat both a LF and CRLF as the "expected" line break right?
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lutβ€’3mo ago
this is at the same time so weird but also understandable, i think i will never forget it πŸ˜‚
hutoanhill
hutoanhillOPβ€’3mo ago
8
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOPβ€’3mo ago
Oh boy that’s a lot of text
MODiX
MODiXβ€’3mo ago
TeBeCo
REPL Result: Success
using System;

var yellowThresholdWidth = 1;
var redThresholdWidth = 2;
var barWidth = 3;

Console.WriteLine($"""
Value
yellowThresholdWidth == {yellowThresholdWidth}
redThresholdWidth == {redThresholdWidth}
barWidth == {barWidth}
""");
using System;

var yellowThresholdWidth = 1;
var redThresholdWidth = 2;
var barWidth = 3;

Console.WriteLine($"""
Value
yellowThresholdWidth == {yellowThresholdWidth}
redThresholdWidth == {redThresholdWidth}
barWidth == {barWidth}
""");
Console Output
Value
yellowThresholdWidth == 1
redThresholdWidth == 2
barWidth == 3
Value
yellowThresholdWidth == 1
redThresholdWidth == 2
barWidth == 3
Quoted by
Compile: 506.782ms | Execution: 30.704ms | React with ❌ to remove this embed.
Unknown User
Unknown Userβ€’3mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiXβ€’3mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server