Comment by bernadus_edwin

2 days ago

Why are so many emulators written in C#?

I can give a lot of reasons:

* C#/.NET is very popular in Europe and in the USA. Probably elsewhere too.

* Performance is great, and greater every November. Especially with Spans, structs for performance critical code (they use the stack and not the heap = less GC pressure), and a recent version of the .NET Runtime. Dynamic PGO (that is profile guided optimization by the .NET JIT at runtime) helps also devirtualize a lot of calls, and all we had to benefit from it was move to .NET 8. Can't wait for .NET 10 !

* Since 2016 (.NET Core) .NET is cross platform and open-source (well minus the link between the .NET debugger and the language server), and the overall SDK (the dotnet CLI tool for example) is absolutely great to work with.

* Using native libs or native memory (there are two pointers in the Spice86 applications, and one is on 'reverse: it is managed memory for the native library to use with the fixed keyword for the time of the call)

* Productivity with VS/Rider for writing/debugging .NET code is through the roof! And the docs are very comprehensive.

* Personnaly, I work with .NET daily, and reverse engineering Dune was hard enough. There's alreasdy a new language in there to understand, and that's x86 real mode ASM written by French devs pressured by time to market, and not very concerned with sane calling conventions...

I don’t think the language is necessarily chosen for the project. I think C# is just a main stream language that a lot of people know.

My guess is portability, then obviously performance.

edit: actually there is a specific answer for this particular project - "We had to rewrite the project in C# to add automated code generation (java doesn't have the goto keyword, making automated ASM translation challenging)". There you are.

  • I mean, that's more or less the reason why it isn't Java, not why it's ultimately C#. My guess is that Java is just what they're most comfortable with, with C# being similar enough but avoiding specific limitations in that case.

    • Wasn't C# essentially microsoft throwing their hat in the ring against Oracle and to show off how cool this .net stuff is?

      I dabbled in both at around the same time a long time ago for console apps and visual studio's autocomplete / assist / library fetch etc made it easier than Java to get working in but...

      Its been so long I forget the origin stories sometimes.

      1 reply →

    • I think my question is why not choose c# for this? What’s the apprehension here if any?