Skip to main content
GameDev.net gamedev.net
🔒 Locked

Why C# all of a sudden?

Started by IceCave Sep 19, 2016 at 4:20 PM 30 replies 16.6k views
Original Post
IceCave
IceCave

For 20 years C++ was the recommended standard language, especially in the gaming industry. Mostly because it is fast and powerful, inheriting most programming language standards you can possibly think of.

There were a lot of languages to come and go, and some stayed.

I.e. Java, since 1995 the most hated of them all (at least how I experienced it).

Considered really slow, JIT is shit and its strong OOP rules and type safety is disabling the programmer or for whatever reasons. Causing (among others) a lot of religion flame wars between believers.

C# is basically a Java copy but with some changes to the base architecture like support for pointers, tuples, structs and more, extending the idea of Java.

Now this isn't a Java/C# comparison or discussion! C# wasn't "well" received at the beginning, either.

However, in the last two/four years I noticed that in general and in this forum C# suddenly got a big popularity boost, including but not limited to gaming industry.

I am neither against nor for C#, I get paid for writing code in a lot of languages, but

What changed? Why is C# or JITs (or for whatever reason Java and C# were hated) acceptable, now?

My personal interpretation for a very long time was Unity and possibly the name "C"# causing a popularity boost among young programming beginners causing old hands to rethink their stance.

Or is it just computers getting more powerful?

Promit
Promit
For 20 years C++ was the recommended standard language, especially in the gaming industry.

In 2001, the C vs C++ debate was still alive and well, albeit fading. In 2008, when I was working on AAA games, the console compilers still struggled with more sophisticated C++ idioms and standard library code (containers etc) were not necessarily bug-free. "C-with-classes" code was still quite common.

C# is basically a Java copy but with some changes to the base architecture like support for pointers, tuples, structs and more, extending the idea of Java.

Of course it's drastically easier to write graphics code with those changes to the base architecture. You're glossing over them but look at Java based GL code and tell me that's not awful.

However, in the last two/four years I noticed that in general and in this forum C# suddenly got a big popularity boost, including but not limited to gaming industry.

Game industry: Unity. On a slightly longer timeline, tools code has been moving towards C# for a long time. It's not much more complex than that.

Outside of games: You're late. C# has seen widespread use in client software development for a long time.

Apart from Unity code, there's relatively little C# game development happening to be honest. There's some adoption of it in the mobile realm, as it's a nice language for shipping across all of the major mobile and desktop platforms all at once.

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Kylotan
Kylotan

I.e. Java, since 1995 the most hated of them all (at least how I experienced it).


Also the most popular of all, at least across programmers in general.

C# wasn't "well" received at the beginning, either.


As far as I can tell it was very well-received in the Microsoft/Windows development community, where they don't need the power of C++ and Java was not a great alternative due to various legal and philosophical issues.

However, in the last two/four years I noticed that in general and in this forum C# suddenly got a big popularity boost, including but not limited to gaming industry.

I am neither against nor for C#, I get paid for writing code in a lot of languages, but
What changed? Why is C# or JITs (or for whatever reason Java and C# were hated) acceptable, now?


Computers kept getting faster, and it became increasingly likely over time that the full low-level control that C++ gives you was no longer strictly necessary for game development purposes.

Unity finally provided the proof of that (with the caveat that the engine itself uses C++; but for the end game developer, that's not important.) And that proof allowed previously hesitant developers to take the risk.

There's also another factor, which is that C++ had a serious competitor in 2D and web gamedev world in the form of Flash + Actionscript. As those technologies got phased out, and with HTML5 slow to pick up the slack, a lot of those developers moved over to Unity and C#. Their games were already proven to run on a VM so this was not a big leap - but it did perhaps mean these people were sharing the same tool as the 3D game developers and no longer ignored by the more traditional gamedev community.
JohnnyCode
JohnnyCode



I.e. Java, since 1995 the most hated of them all (at least how I experienced it). Considered really slow, JIT is shit and its strong OOP rules and type safety is disabling the programmer or for whatever reasons. Causing (among others) a lot of religion flame wars between believers.

Java is a memory managed language, very similar (nearly identical) to C#, but has been poorly implemented, not just performance of its memory manager, but even actual bugging of it, such as memory acumulation over time, uneffective or even absent memory moving and pooling, too long sweep visits of manager etc.

Is it over? Do not know and I do not think.

On the other hand, C# has been an extremly well implemented mem-managed language on Windows NT platform.

C# applications will even outperform C++ aplications 90% of time, since C# will move memory, while static fixed heap allocations of a c++ process will never do so.

In other words, you will have to write top professional c++ aplication to outperform C#, while it is true that ideal c++ will outperform C# clone of instructions always.

C# is thus very popular in game development, it is performative, production safe (c++ can couse leak bugs that can even dump entire projects), fast to work, and it is popular even over the difficulty in actual game development it has, since DX has to be wrapped to be used safely in C#, as GPU can be accessed only thrugh c++ libraries (there are already C#/CLI modules that does the wrap, even official ones such as XNA, but XNA dated out with income of newer DXes).

CLI is the actual bridge between memory unsafe and memory safe modules of a process- what you have stated about pointers in C#, is not entirely true, pointers are in CLI, or unsafe blocks in C# that are not reccomended.

So yes, C# is so great that even gamedev industry desires for it, even if it has the one (difficult) obstacle mentioned.

frob
frob

While JohnnyCode's numbers are clearly made up and has some substantial factual errors, his comment is reflective of common beliefs.

When it comes to tools work I've seen Java stuff since it was introduced around 1995, and I've seen C# tools since about 2003. More recently I've also seen a ton of JavaScript tools relying on NodeJS and similar.

Several game engines have used it for scripting, not just Unity. The Sims 3 engine used C# for all gameplay scripting, and it incorporated C# about the same time Unity did, about 10 years ago.

JohnnyCode
JohnnyCode



When it comes to tools work I've seen Java stuff since it was introduced around 1995,

I too have cried why Java did not shine over. Not even JASP -java active simple pages (as http active serving documents), are not coded at all! Through willigant atempts.

But, I accepted it, Linux is a free, and for free, you cannot get service, maintenance, support, guarentees..... etc. But I still thank to working Linux still, it just cannot compete with payed players :) !

ferrous
ferrous

Unity and XNA and now Monogame are probably the big pulls for C# (And mono, Unity is technically some old decrepit version of Mono). It's also a delightful language to program in compared to C++, depending on what you're doing, of course. At my day job, we use it for all our unit tests, because it's much faster to write, and cleaner than C++, so it's easier to write unit tests and easier to grok what the the unit test is supposed to be testing.

DvDmanDT
DvDmanDT

C# is a really powerful and expressive language that can easily interop with other .NET languages as well as C. It has really good development tools. Performance wise, it's not as fast as optimized C++, but for a lot of use cases it's more than fast enough (faster than many alternatives) with some serious stability and security benefits. It's typically very hassle-free compared to Java and many other solutions on Windows, which is the platform of choice for most gamers and probably also game devs (though this seems to be changing rapidly).

Java was designed with various academic values and best-practices in mind, where C# was designed as a more practical language for real world scenarios. For example, C# has unsafe and P/Invoke integrated into the language. This makes it very good at interfacing with existing code, but is arguably unclean. C# also has both value types and reference types with the same syntax. This can be confusing and is arguably also "ugly", but extremely practical when trying to interface with native code and/or trying to control memory layouts. For things like vector math, vertex arrays and tile maps, this can make a huge difference.

C# has been embeddable since an early age, making it easy to use as a scripting language. It's very easy to use for tools that interface with whatever engine you are using. The overall cross platform support is probably worse than Java etc, but it's good enough on all platforms that are relevant for games.

ChaosEngine
ChaosEngine

Outside of games: You're late. C# has seen widespread use in client software development for a long time.


Not just client. It's been popular in server side for at least 10 years now (between "web methods", WCF, and lately ASP.net web APIs).
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight
WozNZ
WozNZ

The C# language is also fast moving, while it started as a poor mans Java in C#1 it has grown and now Java is trying to play catch up (Apart from the huge drag that Oracle owning it causes). C#6 was a great improvement and added some nice language features and C#7 brings proper tuple manipulation and some basic pattern matching. Even the introduction of Linq raised it far above Java. Most people see Linq as about enumerable types but the reality is that it is more like the computational blocks in F# and can be used for any type that provides a Select/SelectMany pair of functions (Bind and Map in other languages)

Khatharr
Khatharr

C# applications will even outperform C++ aplications 90% of time

xftyHLD.gif

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
BBeck
BBeck

What changed is that we entered the 21st Century and computers are orders of magnitude faster. So, quite frankly, you can waste clock cycles now.

Also, the bottleneck now is the GPU. I have a 7 year old computer with a 3 year old GPU and other than the fact I want to get into VR, there's nothing it can't do really well. I had some trouble last year finding a new CPU with better specs (it was an Extreme processor when I bought it).

The vast majority of the work is done by DirectX or OpenGL and the graphics card. The other stuff will likely run fast enough no matter what you code it in. Seriously. HTML games is a thing now. And that's only going to increase as we go forward. And there's ways to access DX or OGL from just about any language you can program in. XNA/MonoGame is C# running on DX. It's not that much slower than coding directly in DX. (XNA was DX9 based and MonoGame is DX11 based which does not have the advantages of DX12 or Vulkan).

Years ago, I turned my nose up at XNA thinking that "real" game programming was done only in C++. Then I moved into the world of XNA and C#. It made my understanding of Object Oriented Programming far stronger and I never found a place where it would have run significantly better if it had of been coded in C++ with DX. After Microsoft abandoned XNA (which I still mourn because I would probably still be doing XNA if they had not) I moved on to learn DX11 and went back to C++. Then I moved on to OGL with C++. I'm a big fan of both C++ and C# honestly. 6 of 1 and half a dozen of the other. Each have their advantages. For game programming I guess I slightly prefer C++, but that's largely because I'm doing DX and OGL directly. Now I'm trying to learn Vulkan and reading a DX12 book.

But pretty much anything that will let you utilize DX or OGL is more than sufficient these days. That's why Unity is so popular. Even Windows itself is providing more direct access to the graphics card through GDI and whatnot.

As to which tool is best for game development, honestly I don't know. I've chosen C++ and OGL/Vulkan. But I'm not sure there aren't easier or better ways to do it. My experience with XNA and C# was so great I would probably still be doing it if Microsoft hadn't abandoned it.

ErnieDingo
ErnieDingo
C# may not be as fast but it's not an order of slower. Most of the work is in gpu these days. Im actually enjoying coding in c#
Indie game developer - Game WIP    Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)   Insane Software Facebook
jwezorek
jwezorek

Java was popular -- its popularity is for example why Javascript is called "Javascript" even though the two have absolutely nothing to do with each other. Get in a time machine and go back to the late 1990s and see for yourself. People couldn't shut up about Java. Mainly what happened with Java is that client side Java failed. Client side Java failed because

  1. applets failed. Poor design plus HTML/CSS + browsers werent where they needed to be. Java applets should've had access to the DOM which would have allowed Java to be what Javascript ended up being.
  2. AWT sucked.
  3. Swing sucked.

Thus Java for desktop applications and Java in browsers both failed despite Java's enormous popularity. This opened a door for C# which was a better language and WinForms and later WPF were both much better than the early Java gui frameworks. Given the defacto death of MFC with Microsoft not introducing a new native framework they were the only option for writing Windows applications besides 3rd party cross-platform C++ frameworks like Qt, but were also considerably simpler and easier to learn than Qt and in the case of WinForms, were both simpler than Qt and leveraged one's knowledge of Win32 C programming i.e. if you cant do something in WinForms you can always invoke native calls if it comes down to it.

This all led to tools for games, which are GUi applications, getting written in C#. The big down side of writing to .Net -- that it was historcially at least Windows-only -- didnt really effect tools for games because such tools would be used in-house only where a game company could just decree that employees have to use Windows machines to use these tools. Tools like this led to Unity and other engines being written in C# themselves -- which was possible given C#'s speed.

C# really is a better language than Java by the way. It isn't just little things. It's implementation of generics is better in a major way and LinQ is great. LinQ is a great achievement across software engineering, period.

sirpalee
sirpalee
I think there are 3 main factors for this.

- Popularity of unity.
- Tool development at gamedev companies (these are mostly win + c#
- C# is simpler than C++. Easier to start development, and less tols in the beginning to shoot yourself in the foot.

That said, I still prefer C++ at anytime, because I like writing efficient and performant code.
shaken, not stirred
Alberth
Alberth



Thus Java for desktop applications and Java in browsers both failed despite Java's enormous popularity. This opened a door for C# which was a better language and WinForms and later WPF were both much better than the early Java gui frameworks. Given the defacto death of MFC with Microsoft not introducing a new native framework they were the only option for writing Windows applications besides 3rd party cross-platform C++ frameworks like Qt, but were also considerably simpler and easier to learn than Qt and in the case of WinForms, simpler than Qt, plus leveraging one's knowledge of Win32 C programming if one needed it i.e. if you cant do something in WinForms you can always invoke native calls if it comes down to it. This all led I would imagine to tools for games started getting written in C# which led to Unity and other engines being written in C#.
The start was a little different I think. Microsoft tried to 'embrace & extend' trick on Java, but Sun (owner of Java at the time) didn't allow that. The reaction of Microsoft was to create C#, a closed source, Windows-only, programming language. As being the main language at Windows, it received a lot of love from Microsoft, and developed it beyond Java.

Nowadays the language is more open, mostly thanks to Mono I guess.

Khatharr
Khatharr

- Popularity of unity.
- Tool development at gamedev companies (these are mostly win + c#


Those were the two factors that eventually motivated me to pick up C#. Especially the latter one, since WinAPI is a magnificent pain in the ass and VS has a forms editor built in to it for C#.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
jsaade
jsaade

Talking about game industry and not desktop or web applications.

If you are writing a game engine, it would be wiser to go as low-level as you can so you can optimize where you can.

But if you are doing a game, you have a different set of requirements and for me:

- Language should be high-level enough to make sure you do not spend every minute re-inventing the wheel.

- Language should have minimum compile time

The way I see it, taking Unity as an example, the engine itself will always be written in C/C++.

In recent years, every one wants to be a game developer, meaning making games not writing engines.

Unity offers several flavors for scripting, C# is the best one as it is high level, fast compile time and actually you can understand what you are writing.

I am not aware that anything has changed, it is all the same, the target audience changed.

DvDmanDT
DvDmanDT

The start was a little different I think. Microsoft tried to 'embrace & extend' trick on Java, but Sun (owner of Java at the time) didn't allow that. The reaction of Microsoft was to create C#, a closed source, Windows-only, programming language. As being the main language at Windows, it received a lot of love from Microsoft, and developed it beyond Java. Nowadays the language is more open, mostly thanks to Mono I guess.


Well, yes and no. IIRC, the official implementation was closed indeed, but it was standardized from an early age and all blocking patents were released under some "community promise". So it was an open language with a closed implementation. I think Java was a closed language at the time, not even sure if an open implementation existed. There was some shared source reference implementation of .NET ("SSCLR" or something), but the license was bad.

There were two open source implementations of .NET, Mono and something like DotGNU or similar. What caused them to fail early on was some patent problems. Microsoft held patents which effectively blocked other implementations. They gave some promise that other implementations were allowed to use that tech, but the promise was legally weak. Then they made some pact with Novell (developer of Mono at the time) to not sue eachother over patent infringement, but it still didn't sit well with the OSS community. Here's a quote by Stallman:

Debian's decision to include Mono in its principal way of installing GNOME, for the sake of Tomboy which is an application written in C#, leads the community in a risky direction. It is dangerous to depend on C#, so we need to discourage its use.
The problem is not unique to Mono; any free implementation of C# would raise the same issue. The danger is that Microsoft is probably planning to force all free C# implementations underground some day using software patents.
...
https://www.fsf.org/news/dont-depend-on-mono


I think large parts of the die hard OSS community is still sceptical for these reasons, but now that .NET and mono are truly open source, more and more people are becoming interested due to the technical merits. I'm personally hoping it'll gain significantly over the next years, but we'll have to see about that..
Ravyne
Ravyne

C# is a rather ergonomic language coupled with expansive, inter-operable libraries and generally great tooling. It performs well enough, and even though highly-tuned C++ will never lose to even highly-tuned C#, a great deal of typical code will never receive that kind of attention -- in many non-gaming applications, perhaps no code at all gets that kind of attention. I would argue that non-performance-critical code created by a typical C# developer is cleaner, more maintainable, and makes better use of libraries than the typical C++ developer likewise creates for non-performance-critical code. I would further argue that the C# developer can do it in less time and be within a reasonable margin of performance, even winning in some cases. I would note that idiomatic use of the latest C++ language/library features can mitigate, or perhaps even overturn that relationship, but almost no one is really embracing that yet and there's a ton of legacy C++ out there that's difficult to move off of the old idioms. CPU cycles aren't infinite, but they're abundant and cheap -- If I've got more cycles available than what I need, its perfectly reasonable to spend some of them on my own improved productivity as a developer.

Neither language is going anywhere though--C++ stalled and even retreated a bit during the period between about 1998 and 2011, but the recent standards work has put its prospects on a steeper upward trajectory than ever before. That's not hyperbole, that's what the stats and trends are showing. Recent and upcoming standard advancements have really made it a better language.

C# is doing similarly well -- .Net Core and the open-sourcing of pretty much all of the C#/CLR/.Net Framework ecosystem is going to make for a better future too. Its effects are already feeding into Mono, Unity, and in other ways. All the desperate .Net implementations are moving towards parity, if not unity.

And its not zero-sum -- a rising C# isn't going to cannibalize C++ entirely, nor is a renewed C++ going to cannibalize C# entirely. They'll each be given as much work as they're fit for, and there's plenty of work to go around. Its a symbiotic relationship when you think about it -- A competent C# allows for C++ experts to focus their attention where its most beneficial, expands the hiring pool, and has allowed people and teams to create a wealth and variety of games that never would be created with C++ because the expertise or efforts required are too high a hurdle.

throw table_exception("(? ???)? ? ???");

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.