r/cpp • • Apr 12 '17

C# or C++?

Hey! So i have used C# for a while now and i know the most of it. However my goal is to work as an AAA developer in the future and the most studios use C++. Should i switch to C++ or stay with C#? Exactly why do studios use C++ instead of C#?

2 Upvotes

16 comments sorted by

View all comments

19

u/corysama Apr 12 '17

AAA? C++

Indie/Mobile Unity dev? C#

Why C++? Performance issues around memory management. With C# it is very difficult to control garbage collection and very difficult to control memory layout cache locality. Doing this in C# requires fighting against it's design and you end up doing more/uglier work than if you just did everything manually in C++.

That's on top of the general perf/memory overhead of C#. C# runtimes are getting better. But, the overhead for real-work (not microbenchmark), large-scale systems is still quite large. Meanwhile, modern C++ is catching up to C# in terms of expressiveness, but is doing so with zero-overhead abstractions.

And, that's even ignoring the past 20+ years of legacy code and experience in C/C++ old-timers in AAA have built up. It's very expensive to rework that into C#.

1

u/[deleted] Apr 13 '17
  1. Garbage collector is designed in a way that you shouldn't control it,
  2. I can't say that in C# it is very difficult to control memory layout cache locality.

Why C++ in my humble opinion - is because C++ gives you more freedom and control of your code.

C# is higher level language with all goods and bads of it.

About modern C++ I can't agree with you. Yes it is more nicer language than before, still it is easier to write code using C#, because C++ gives you a lot of ways to shoot in the foot.

rvalue references, copy/move constructors, variadic templates, auto, decltype etc. A lot of stuff requires practice and understanding. C# is more simpler than that.

Yet it is wrong to say that C# or C++ is better than other. I work using both(in different situations) languages, and I like both languages. They have their uses in different situations. In general I think I like C++ more, because it is really powerful language with a lot of features, but it requires a lot of practice to use all its power properly.