Hacker News new | ask | show | jobs
by dzonga 1003 days ago
quick qn for game dev's ?

why was C# adopted for game dev ? compared to java given that they're both similar langauges which use a vm.

I do understand that C# has a better native interop story. than java.

and probably the only notable jvm based game was minecraft

9 comments

I'm not a gamedev, but my hypotesis is that one of the reasons is that Mono license at the time was way friendlier than risking having Oracle on your neck.

Modern C# also has more features that help avoid allocations, which in turns reduce GC pauses, which are the biggest enemy of a game

Unity and XNA, but mostly Unity.

Unity used Xamarin to target iOS and Android, so this meant using C#. As Unity's popularity grew, so did the use of C# in gamedev.

XNA was a very well-designed game framework (not engine) that allowed many people to get into indie gamedev without learning C/C++ and SDL or OpenGL. Java had nothing comparable, libGDX was released only in 2014. If you followed one of the indie stars and tried to emulate them, you were quite likely to learn XNA or one of its reimplementations.

IIRC they were using Python initially. Turned out it was way too slow (also it was the mid 2000s).

They hired the guy who created Boo (a python like programming language) and switched to Mono (I'm not sure why they picked it instead of JVM I guess it was possible related to licensing but because they just had people who were experienced with it).

Also C# wasn't even their primarily programming language until 2012-2014. It was UnityScript (JS like syntax running on Mono). The idea was that C#/static typing was too scary/complex for most of their uses.

I think its adoption was mostly influenced by XNA. A lot of small (and big) games used the XNA libraries, and by extension the .Net framework and C#.
Java is also adopted by game devs, even if to lesser extent, many mobile games, J2ME and Android, Minecraft, game tools.

However CLR has support for AOT and C++ since day one (even if NGEN isn't that great and only covers specific cases.

C# has thus access to the CLR features needed for C++, while exposing them in a more developer friendly way, and since C# 7 many of those features that required direct MSIL manipulation are being exposed as language features, making it even more easier to use.

C# has had mono which was open source and designed to be embedded, and now we have coreclr, which is also designed to be embedded, very easily. Meaning you can write critical parts of your engine in C/C++ but run C# for core gameplay logic and plugins/extensions.

The JVM isn't/wasn't the greatest to embed and it's kind of a lumbering beast even today.

Also you aren't embedding C#, but dotnet, with which you open yourself up to an entire ecosystem of languages (if you really want to write plugins in VB.NET or F# or IronPython), and a ecosystem of libraries and even Microsoft tooling that's way more polished than Oracle/Sun ever put out.

Do you mean why Unity adopted it, or why people generally use it for game dev?

Unity uses C# for historical reasons - when Unity started, Mono was one of the few options that fit their needs. Outside Unity, C# mindshare isn't that big I think.

Java has been used a fair bit for Android games for obvious reasons, but game programmers are rarely Java fans.

For anyone interested, LibGDX[1] is a very nice open-source game engine for Java. It is cross-platform (mobile, PC/mac, web). Very popular and well maintained, too.

[1] https://github.com/libgdx/libgdx

Probably because most games target Windows.