[=nlaq;17660]
This thread is silly.
People are correct in saying that C++ can outperform C# (either MS’s CLR or Mono’s) if written correctly. However, writing performant code in any language isn’t a trivial task. Just writing in C++ isn’t going to give you any automatic performance boost. Just as with managed code, much care needs to be taken in how you [de]allocate memory, exploit caches and architect your code.
There very much is a sort of poisonous mentality in the games industry that native code is the only appropriate choice for all game and engine logic. I think this comes from inexperienced developers who heard someone say once that C++ can outperform C#, and didn’t take the time to understand the context of that sentiment. Frankly, I wouldn’t trust a developer who makes the blanket claim that C++ is the only correct choice in game development to have the experience or knowledge to correctly use C++ in the first place. The whole thought process behind people pushing C++ as the only viable language in games reeks of immaturity and unprofessionalism. An alternate explanation is that C and C++ are taught at many schools for programming and game development (for good reason: learning C++ is an excellent experience that I wish on all programmers who want to further their skills).
[/]
I don’t think any blanket statements have been made advocating C++ as the only solution to any problem. I think the case has been made that there are downsides to any managed language, and that C# and IL languages in particular lack the comparative speed and language features relative to C++ and therefore make it a less optimum choice for a large complex real-time application.
No one is trying to make some kind of crusade for or against any particular language here.
Just to remind you the original question on this thread was why Epic had dropped UnrealScript in favor of C++ and Blueprints.
[=nlaq;17660]
- Writing performant code is difficult and requires rigorous testing and deep knowledge of general computation and the specific algorithms used in this domain. A person with good programming sense can easily write managed code that outperforms native code written by someone who lacks the proper background and experience. Please don’t push C++ because “it’s faster” if you do not understand, for example, cache lines or proper memory allocation.
[/]
This is a bad generalization in my opinion. Domain specific knowledge is critical in certain classes of problems, but that does not mean that language choice is irrelevant by any means. There are trade-offs.
Generally speaking, across an application, C# is slower than C++, ranging from 2x to possibly many times slower… Pointing out that an expert programmer can write code that outperforms a monkey banging on a keyboard in C++ doesn’t really make that fact any less true.
That fact in no way means that C# or other managed languages are a poor choice for games. Minecraft was written in Java and it runs just fine.
But UE4 is meant to push the bleeding edge. Potentially losing a factor or 2x or more off the top of a program just based on your choice of language before you write any code at all is a discussion worth having.
[=nlaq;17660]
3) Ease of use. Ease of use is not an excuse for non-programmers to be able to write code - on the contrary. I use this term to say that a language such as C# will allow an experienced developer to write correct code more quickly; and give them the tools to architect their logic in such a way as to promote reuse and modularity (thus decreasing the amount of time required for maintenance, fixing bugs, prototyping or adding new features).
[/]
These generalizations apply equally to C++ and C# and to any modern programming language, including Blueprints.
[=nlaq;17660]
So what exactly am I suggesting? Basically: Unity’s scripting model. I’m not going to go on a general U4 vs UE5 debate here: but I think one of the things that the Unity folks did better than Epic was expose a scripting API in C#. People can, and will continue to, write poor C# in Unity that negatively impacts performance - but the vast majority of the time, properly written code has no noticeable impact. The architectural and stability advantages are very much worth the insignificant performance penalty.
[/]
There are no inherent stability advantages or disadvantages inherent to either language, except for garbage collection. The good and bad of GC in a real-time application is a big topic. It’s also not a trivial issue. GC cycle hitches in Unity are a real issue.
The expressive power of C++ as compared to C# allows for significantly more elegant and powerful code architecture. Slate in UE4 is a good example of this. In-fact the entire Unreal Object system is a living breathing example of the type of architectural expressiveness allowed by C++ that would never be possible in C#.