🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Has C# replaced C++?

Started by
70 comments, last by Prototype 4 years, 10 months ago

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

Advertisement

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.

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.

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...

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.

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.

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)

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.

 

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.

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.

This topic is closed to new replies.

Advertisement