30.1.12

C++ vs. C#

This list is by no means complete and I might correct/extend it over time.

Pro C++:

  • Many reasons for C++ are collected at the C++ FAQ.
  • Low memory/clock cycle overhead for atomic operations.
  • Widespread. C/C++ compilers available anywhere.
  • C++11 adds functional programming facilities, threading, foreach-loops, type inference and more. But this is not yet completely implemented on all platform. Each LLVM, GCC and VC++ miss various different parts of it.
  • Big choice in IDEs: Eclipse CDT, Xcode, Visual Studio, ...
  • Many libraries available (though not all portable).
  • Big freedom in adjusting the language to personal needs by using template meta-programming.
    • Also many duplications of facilities. Many many ways to achieve one thing.
  • Closer code to assembly mapping.
  • Compiles to native assembly. Decompilation hard by default.
  • More compile time optimizations.

Pro C#:

  • Many reasons against C++ are collected at the C++ FQA
  • More runtime optimizations (JIT). Less compile time (AOT).
  • Debugging seems fine on all platforms. For C++ some platforms are tricky (e.g. on Android).
  • Regions! Incredibly useful for grouping code sections.
  • For 2D games there is a nice portable API sparing the programmer from implementing messy boilerplate code: XNA (and its free and portable implementation MonoGame).
  • Better tool support (since the language syntax itself is simpler and allows easier parsing).
    • Significantly better refactoring. Comparable to Eclipse JDT. Plugins like ReSharper even go beyond.
  • Almost instant compilation and edit&continue (a.k.a. hot swapping). No minute long compile times with many thousands of lines long header files being parsed over and over again for different modules.
  • No include and linking madness. Using third party frameworks similar to Java: Adding a reference to the library (one .dll-assembly-file). Optional .dll.xml for library also adds documentation. Usage as simple as giving full namespace path or "using Lib;".
    • Thats result of a modern build system. C/C++/ObjC are outdated in that respect.
  • Also available on Windows Phone 7 and Xbox 360 (might change later).
  • Base class library in scope comparable to JFC.
  • No strict separation of declaration and definition. Hence less forced code redundancy since method signatures don't need to be synced between headers and actual code modules. This implies there is usually only one file per class (though C# does allow splitting classes of files using partial classes and also having more than one class per file).
  • LINQ: SQL'ish data queries for arrays, collections, XML, ... shortens many game logic related functions significantly.
  • Functional programming facilities. Mostly that means having lambdas. Type inference (var-keyword). Many things C++11 introduced are in C# already fully available on all relevant platforms.
  • Nice and simple syntax for things like generics and object initialization.
  • Properties are superior to getters/setters.
  • Commercially supported Android and iOS solutions (Mono for Android respectively MonoTouch).
    • No messing with abysmal NDK, JNI, Objective C crap.

0 Comments:

Post a Comment