DEV Community

Discussion on: Should you pick C# over JS? Maybe.

Collapse
 
denvercoder profile image
Tim Myers

And forget about stuff like

[] + [] = ?
{} + [] = ?
[] + {} = ?
0.1 + 0.2 = .300000000000004
1+2 = 3
1+2+3 = 6
1+2+3+"4"= "10"

Collapse
 
peerreynders profile image
peerreynders • Edited

0.1 + 0.2 = .300000000000004

double a = 0.1;
double b = 0.2;
Console.WriteLine(.1F + .2F == .3F);        // False
Console.WriteLine((.1F + .2F).Equals(.3F)); // True
Console.WriteLine(.1D + .2D == .3D);        // False
Console.WriteLine((.1D + .2D).Equals(.3D)); // False
Console.WriteLine((a + b == .3D));          // False
Enter fullscreen mode Exit fullscreen mode

Stones and glass houses.

The C# compiler is permitted to give either answer to that question at any time for any reason. You can compile the same program twice and get different answers. You can ask the question twice in the same program and get two different answers.

Other than that it's just the usual IEEE 754 weirdness.

What Every Programmer Should Know About Floating-Point Arithmetic

JavaScript's sin was to base its core numeric type entirely on a floating point representation.


PS: And how well do you think will a client-side Blazor app be running on something like a Moto G4?

Don't get me wrong, client-side Blazor will be a boon for MS shops for implementing internal enterprise web apps - but the public web is about reach and that means dealing with the lowest common denominators in terms of client device computing power and connection quality.

As it is the current JS ecosystems will need to go on a serious diet to keep the web relevant.