2 ms·
At the very end of the blogpost the author asks why not compile C# to JavaScript, like F# (Fable) does? The author thinks that would be the best solution overal
by azakai 3y ago
At the very end of the blogpost the author asks why not compile C# to JavaScript, like F# (Fable) does? The author thinks that would be the best solution overall, and is surprised it has not happened yet.
In fact that has happened, see JSIL (http://jsil.org/ http://jsil.org/, which compiles .NET bytecode to JS) and also SharpKit (https://github.com/SharpKit/SharpKit https://github.com/SharpKit/SharpKit which is built on Roslyn).
But this will not necessarily be any better than compiling to wasm. It avoids the .NET interpreter, which decreases the download, but it will still need to bundle a lot of library support code. And getting the language semantics exactly right - including features like C# finalizers which do not have direct support in JS - is tricky, unlike with wasm. And it won't benefit from the speed of the wasm implementation in AOT mode (which Blazor supports), which can be much faster than JS.
Compiling to JS definitely still makes sense in some cases, but it isn't an idea that Microsoft or the .NET community has somehow overlooked. It has been done and it has its own tradeoffs.