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

Has C# replaced C++?

Started by Boder Aug 16, 2019 at 11:33 PM 70 replies 64.4k views
Original Post
Boder
Boder

Dear GameDev,

I haven't been programming in a while. My question is: has C# replaced C++ for programming and game programming? Or has another language even superceded C# (D, Swift)?

I was programming in C with some of the features of C++. I'm downloading Visual Studio. Should I just learn C#?

Thank you

Boder
Boder

I found this topic on "Language Programming"

Which I passed up before because of the name. It looks like C#/Unity is the new good combo.

Nypyren
Nypyren

C# does not replace C++. However, you should learn C# anyway because it's an extremely useful and nice to use language.

You can make games in C++. You can make games in C#. But neither is completely better or worse than the other.

Boder
Boder
27 minutes ago, Nypyren said:

C# does not replace C++. However, you should learn C# anyway because it's an extremely useful and nice to use language.

You can make games in C++. You can make games in C#. But neither is completely better or worse than the other.

I found this topic, which looks like the one to read:

Now that I think about it, the choice of engine/libraries is almost as important as the language. Their were a couple of things I didn't like about C++: a big one being how it was completely mixed up with C, but also memory leaks, difficulty debugging, having both references and pointers, redundant header files...

Nypyren
Nypyren

Most of the little annoyances that C++ has (headers, memory management) are gone (or significantly easier to deal with) in C#, but there are still some weird things that won't work as you'd expect until you learn how the nuances work.

Make sure to focus some attention on learning how C#'s reference and value type differences work, since it's significantly different from C++. In C#, the reference-ness or value-ness of something comes from whether its type uses a class or struct keyword, instead of C++'s & or * on each variable (or lack thereof). C# classes are always allocated on the heap. C# structs are allocated based on where the variable is defined (and can be allocated on the stack even with the 'new' keyword).

At work I use the Unity game engine with C#, and it works pretty well. Unity has a handful of minor annoyances, but those are insignificant compared to what we used to face when using C++ with various middleware.

There are also some things which are better in C++. RAII is simpler to use than C#'s 'using' statement (until C# 8 comes out, anyway). C++ templates are MUCH more capable than C#'s generics (although it's extremely rare when I find myself wanting C++'s template capabilities). For example, C# has no way to make a generic function with variadic arguments like C++ has, such as if you wanted to make a generic function that can call different classes' constructors. The closest you can get is the 'params' argument qualifier, but that is much more restrictive than C++ variadics.

Lucrecious
Lucrecious

C# is a great language but it is really only fully compatible with Windows due to its .NET dependency. As such, C# does not at all replace C++.

Godot has C# integration with mono and I've heard it's pretty good, but I seriously wouldn't trust the port yet.

Aside from that, C# is unequivocally designed better than C++, in my opinion. Yes, C# is garbage collected but you're also able to work with unsafe pointers and memory manage yourself. C++ pretty much requires the usage of header files which are a completely and utterly antiquated concept and design flaw that only exists to keep the compatibility with C (again, my opinion). C# is a lot more deterministic than C++, so IDEs have a much easier time refactoring, finding definitions/references and catching errors before you even compile. C# also has much better security compared to C++.

If you can't tell, I'm not a fan of C++, it's not fun to use, it's horrible to debug, and it's hard and boring to maintain. The only reason it's so widely spread is pretty much because it's so widely spread. And the only reason it's my main programming language is because my team uses at work.

All good.
Nypyren
Nypyren
37 minutes ago, Lucrecious said:

C# is a great language but it is really only fully compatible with Windows due to its .NET dependency.

This is very outdated.

.Net Core is fully supported on (at least) Windows, OSX and Linux. At work we've been using it heavily on Linux to run an ASP.Net Core server with all of our code in C#, and haven't had any issues yet. Our individual developers use OSX and Windows and we can run the same exact ASP.Net Core server on our own machines without having to write any platform specific code whatsoever.

The Unity game engine supports Windows, OSX, Linux, iOS, Android, WebGL, several of the modern gaming consoles. Occasionally you need to write platform-specific code, but C# runs on all of them. Unity has a custom version of .Net which has been updated to be (mostly) in line with .Net Standard 2.0 (NOT related to .Net Framework 2.0)

Green_Baron
Green_Baron

I never got monodevelop to run (standard debian) without crashes; segmentation fault or just silently. And one depends on the promise that Microsoft will not execute its right on their parts of the software. I wouldn't see it (C#) as alternative to C++ (or Unity to other engines) on Linux

Does Unity still depend on chrome sandbox ? On the danger of being divisive, but i can't avoid considering that to be a rootkit by google to cancel out the Linux user access rights ... i may be wrong, no question.


Nypyren
Nypyren
6 hours ago, Green_Baron said:

Does Unity still depend on chrome sandbox ? On the danger of being divisive, but i can't avoid considering that to be a rootkit by google to cancel out the Linux user access rights ... i may be wrong, no question.


I can't say. We only run Unity on our developer machines (OSX, Windows) and end-user devices (iOS, Android, and WebGL). Our Linux servers don't run Unity at all.

Gnollrunner
Gnollrunner

I personally don't think C# will ever replace C++. Maybe something else will, at some point in the distant future. C# is a byte code compiled / JIT language and has a garbage collector. I realize MS has added features to optionally work around both these things but they weren't originally part of the concept. My feeling is to get to the point that it has the performance to really replace C++, it will end up being just as hacked up as C++ has become if not more. If I'm going to use a hacked up language, I might as well use one that is not so closely tied to a single company. With C++ at least you can just ignore the features you don't like and work with a subset.

Bregma
Bregma

At least one popular commercial game development product uses C# as its primary development language. Because of its popularity among independent and hobbyist developers, you will encounter a lot of C# questions and code in game developer social media. It's sort of a selection bias. You might find most big commercial game development shops don't use these third-party tools (and don't use C#), but then again they don't hang around on social media asking about how to use their tools, either.

It's interesting to note that the products that provide a C# interface for customers are themselves written in C++. If you want to go deeper, it's also interesting to note that the C++ runtime is itself written in C, although most modern C toolchains are written in C++.

Stephen M. Webb
Professional Free Software Developer
Lucrecious
Lucrecious
19 hours ago, Nypyren said:

This is very outdated.

That's fair. I actually worked a little bit on the team porting .NET over to Linux - it wasn't all ready for the public when I was there.

I've tried getting monodevelop to run on OSX, but was too lazy after trying to troubleshoot issues with crashes. Maybe if I tried a bit harder I could get it to run haha

5 hours ago, Gnollrunner said:

My feeling is to get to the point that it has the performance to really replace C++,

I don't believe C# will ever get to the point of beating C++ in performance, albeit the performance difference is pretty negligible for most problems right now. C# getting faster than C++ is pretty much impossible as long as C# is GCed. That being said, I don't think performance was ever the main objective, I believe C#'s main objective was to improve on C++'s faults while maintaining flexibility and usability. In other words, C# wasn't made to be fast, it was made to be easy and fun to use - which it is haha

All good.
TMII
TMII

No, it has not replaced C++, neither in game development nor in any other programming league. Choosing any tool over any other for everything is fundamentally a mistake.

C# does not even come close to the most demanded languages in industry, which is by far JavaScript, Java and C++ in basically all technological fields. Also of note here is Google's Go and Python in engineering and scientific fields. It is a trending programming language but so is Rust (-> C++) and Kotlin (-> Java) and I highly doubt it is going to beat those on the long run.

Choose the right tool for your task, switch if nescessary. Don't hesitate. Don't be afraid.

Gnollrunner
Gnollrunner
50 minutes ago, Lucrecious said:

albeit the performance difference is pretty negligible for most problems right now.

You'd have to prove that to me. IMO if that was really true C# would be taking over the industry, and I don't see that happening.

Quote

C# wasn't made to be fast, it was made to be easy and fun to use - which it is haha 

"Fun" is kind of subjective. "Easy" is even kind of subjective. With C# I would probably be banging my head trying to get round the GC. But if it's working for you, then great.

Lucrecious
Lucrecious
1 minute ago, Gnollrunner said:

You'd have to prove that to me. IMO if that was really true C# would be taking over the industry, and I don't see that happening.

"Fun" is kind of subjective. "Easy" is even kind of subjective. With C# I would probably be banging my head trying to get round the GC. But if it's working for you, then great.

I feel like this is a little bit of a dishonest take though. The reason C++ is industry standard has to do more with the dependencies on legacy C libraries and less so on performance. The reason C# isn't taking over is because it's relatively new in cross platform compatibility and probably a load of other factors.

You complaining about getting around the GC in C# is like complaining getting around dynamic variables in dynamic programming languages. Sure, you can work around them, but you'd be going against the language's design paradigm. It's not the same as me complaining about header file maintainence on C++, they're completely useless and part of C++'s design paradigm.

GC has been proven time and time again to only be negligibly slower than memory management for many problems, it's partly why Java, as much as it is annoying to code in, is so widely spread. C++ is really only needed when performance is an issue to begin with, otherwise it's not useful at all.

But anyways, this is turning into a C++ vs C# thread instead of whether or not C# will be replacing C++. I'll let you have the last word on this topic if you'd like.

All good.
TMII
TMII
1 minute ago, Lucrecious said:

it's partly why Java, as much as it is annoying to code in, is so widely spread.

Since C# was and still is a plain Java copy from Microsoft and since both have developed in parallel nearly in the same direction during the last ten years, I wonder what you are speaking about. Syntax, functionality and philosophy wise they are basically the same with a different naming scheme. It takes a few minutes and a bit Stackoverflow to switch between both languages for a skilled programmer.

Not so easy with C++ because it has a totally different design philosophy. It's not enough to simply know a syntax, you have to think in a language. It is increadibly difficult to switch between C++ and C# mind-wise.

People switching from one language to another often complain about random things in the first days because they are still stuck in another mindset, not being able to find the same solutions for the same problems. For their own worst case scenario they dismiss it completly. Luckily it keeps being their own problem.

Lucrecious
Lucrecious
1 minute ago, TMII said:

Since C# was and still is a plain Java copy from Microsoft and since both have developed in parallel nearly in the same direction during the last ten years, I wonder what you are speaking about.

You thinking C# and Java are functionally the same is pretty simplistic, sorry. I've only heard first year university students say this. Java just by merely enforcing every class method to be virtual already requires a different programming technique.

All good.
Green_Baron
Green_Baron
Spoiler

Time to get me a beer and peanuts ?


TMII
TMII
30 minutes ago, Lucrecious said:

You thinking C# and Java are functionally the same is pretty simplistic, sorry. I've only heard first year university students say this. Java just by merely enforcing every class method to be virtual already requires a different programming technique.

I ask you kindly to refrain from such statements in the future.

I understand this discussion got a bit heated with C#/C++ already. I am ending this discussion from my side now with a last statement that such a trivial thing is not even nearly comparable switching between any other two languages, especially from or to C++.

Gnollrunner
Gnollrunner
2 hours ago, Lucrecious said:

I feel like this is a little bit of a dishonest take though. The reason C++ is industry standard has to do more with the dependencies on legacy C libraries and less so on performance.

"Dishonest" implies I'm lying. I simply disagree . For a long time Java and C# had horrible performance compared to C++. I bench marked them many times over the years. Java in particular was pushed very hard at the department I used to work in at intel, and programmers ended up pushing back mainly because of performance issues. It has more recently done a lot of catching up but it's still not there yet. Same goes with C#

Quote

You complaining about getting around the GC in C# is like complaining getting around dynamic variables in dynamic programming languages.

I don't complain about dynamic variables in many languages that use them, because they typically don't hurt the target usage. Requiring the use of a GC in a systems, or even applications programming language is constraint that effects how I can handle memory management and therefor can effect performance.

Quote

GC has been proven time and time again to only be negligibly slower than memory management for many problems

Proven by who? Even in C++ I rarely use the standard heap. Most of my memory management is done with a custom heap library I have built up over the years. Most of the time I'm using some flavor of slab allocation, where new gets inlined as a free list pop. Also if I don't need thread safety for a particular heap it's turned off. I don't think you have that level of control in C#.

Quote

C++ is really only needed when performance is an issue to begin with, otherwise it's not useful at all.

i.e. Cutting edge 3D games and other math intensive and mission critical software. It's all relative. If performance really isn't an issue we can write everything in Python.

If C# works for what you are doing then go ahead and use it. I'm certainly not telling anyone what language they should program in. However C++ still exists because there is a need for it.


Topic Locked

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

Sign in to reply to this topic.