What are the most important things that should make me consider moving to C++?

Started by
46 comments, last by Washu 11 years, 7 months ago

- Code will compile to just about any platform

I actually missed this one the first time around. It should probably say something more like "Code can be beaten into compiling on just about any platform, given a significant porting effort".


  • Want to compile your 32-bit code with a 64-bit compiler? Sorry, your standard integer type changed size, and nothing works anymore.
  • Want to compile your standard-conforming code on Android? Sorry, we disable RTTI and exceptions, just because.
  • Want to compile your file-system tool on Windows? Sorry, we only kind-of support POSIX over here.
  • Want to compile your file-system tool on Mac? Oh, hey, we do support POSIX, but we moved all the header files.
  • Want to compile your GUI application on a Mac? Sorry, we don't have Win32 or MFC. We do have GTK+ and QT, but they have subtle differences from their linux counterparts.



Even though a number of those points are library related, when you compare to the portability of a language/ecosystem like Java, C++ just doesn't cut it.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Advertisement
To extend on the above, C (and hence C++ by 'inheriting' most of C) was designed to be a portable replacement for assembly languages -- i.e. it's "portable" in that you don't need to learn the actual assembly instructions for each CPU that you want to port your code to, but you've still got to port your code.
Same with any language / platform.

C# using Winforms on Android isn't going to work.
C# using Gtk# on the Windows Phone isn't going to work.

Unfortunately because C++ has many more platforms to support and includes loads of legacy support, people get put off by this and consider to be harder.
http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

Unfortunately because C++ has many more platforms to support and includes loads of legacy support, people get put off by this and consider to be harder.


That's not the argument.

The argument is that "C++ is way better for portability", and to get that awesomesauce, you deal with C++'s downsides. In real life, C++ isn't that portable. So you have the same portability issues in C++ as you do in other languages, except C++ also has all these other downsides.

C++ isn't that portable.


C++ isn't as portable as C perhaps. But far more so than C#. It doesn't need a runtime VM for a start ;)

In terms of games library portability... Writing a library in C or C++ (or another native language) is perhaps the only way you can guarentee it can work in C#, Java, Python.

You can't use C# libraries in python for example.
http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

[quote name='GrandMaster789' timestamp='1347617031' post='4980011']
Detailed, explicit control over your application


Eh? You don't even know the size of your int's...
[/quote]
Sure we do, it is sizeof(int) :P

[quote name='GrandMaster789' timestamp='1347617031' post='4980011']
- Code will compile to just about any platform

I actually missed this one the first time around. It should probably say something more like "Code can be beaten into compiling on just about any platform, given a significant porting effort".



  • Want to compile your 32-bit code with a 64-bit compiler? Sorry, your standard integer type changed size, and nothing works anymore.
  • Want to compile your standard-conforming code on Android? Sorry, we disable RTTI and exceptions, just because.
  • Want to compile your file-system tool on Windows? Sorry, we only kind-of support POSIX over here.
  • Want to compile your file-system tool on Mac? Oh, hey, we do support POSIX, but we moved all the header files.
  • Want to compile your GUI application on a Mac? Sorry, we don't have Win32 or MFC. We do have GTK+ and QT, but they have subtle differences from their linux counterparts.



Even though a number of those points are library related, when you compare to the portability of a language/ecosystem like Java, C++ just doesn't cut it.
[/quote]


And then you start thinking about more game-like issues , such as direct memory access and , let's not forget, execution speed, and then you see the light :D
C++ is a 3rd generation language.
Only generation 0 (opcodes) and generation 1 (assembly) are considered low-level.

Fortran, Pascal, & C are 2nd generation languages.
Objective-C, C++ is 3rd.
Java & C# are 4th.

Language choice is dictated by the quality of the toolchain available for your target platforms.
If you only want it to work on Windows, use C#.
If you only want it to work on Android, use Java.
If you only want it to work on OSX, use Objective-C.

If you want it to work on all three, then you need to setup your environment to build and test for all three.
I would probably setup a C# environment using .NET, Mono, & Ximian.
If you know Java well, then setup a Java environment.
If/when you need to do something lower-level, then you use C++ or C.

Java would probably be easier but I would look into what is new for JNI and GUI before I committed.
Those are the two areas that Java always seems to fall apart. For example C# now has C++/CLI & CXXI for native-interop in addition to the features built directly into C# & WinForm is now supported by Mono so that nails the JNI & GUI problems.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

You can't use C# libraries in python for example.


That's not strictly true... IronPython.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

That's not strictly true... IronPython.


You can't use C# libraries in Objective C for example.


If you only want it to work on Windows, use C#.
If you only want it to work on Android, use Java.
If you only want it to work on OSX, use Objective-C.


Or cut the crap and use the langage and compiler that works for all.

Windows: C++ (GCC)
Android: C++ (NDK, GCC)
OSX: C++ (GCC or Clang)

And if you code your software correctly, you can get code that works on all without needing to rewrite your software in a new language each time.
http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

This topic is closed to new replies.

Advertisement