Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • This topic is locked This topic is locked
47 replies to this topic

#21 swiftcoder   Senior Moderators   -  Reputation: 9636

Like
1Likes
Like

Posted 13 September 2012 - 02:57 PM

I should just write it up one day and link to it.

Hah. I was just thinking about this the other day.

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


Sponsor:

#22 KappaG3   Members   -  Reputation: 131

Like
0Likes
Like

Posted 13 September 2012 - 03:54 PM

Oh, wow. Just have to go away some hours to find the exact opposite of what I got told yesterday.

I want to learn C++ mainly because I never worked with low-level languages, and because I'm sure it'd be a great learning experience.
I also tought that its libraries would make life as easy as it is with XNA, but I think I'm wrong after seeing all those replies.

I have the solution: I'll keep studying C++ as a hobby, while continuing my C# projects.

#23 LordJulian   Members   -  Reputation: 151

Like
2Likes
Like

Posted 13 September 2012 - 04:41 PM

It boils down to whatever you want to do... You want to be productive now - stick with what you've got, as long as it works for you. You want to learn a lower-level language and have the determination to feel stupid again without giving up (because switching will, at times, make you feel that way), then go ahead onto C++. What C++ has for you ... it's the de-facto standard for any "serious" (read consoles + PC/MAC) game dev company (I should know, I've been working for one for 6.5 years). If you want to code an xbox game (short of little XNA games), you will do it in C++ at least at some level, because the sdk they offer is for C++; want to code something for PS3... yep, C++ sdk as well... So, just define your goal: productivity now or study_now_reap_benefits_later. If you're determined and willing, I see NO reason not to go into some C++ programing. Have fun!

#24 Washu   Senior Moderators   -  Reputation: 4487

Like
4Likes
Like

Posted 13 September 2012 - 04:45 PM

Oh, wow. Just have to go away some hours to find the exact opposite of what I got told yesterday.

I want to learn C++ mainly because I never worked with low-level languages, and because I'm sure it'd be a great learning experience.
I also tought that its libraries would make life as easy as it is with XNA, but I think I'm wrong after seeing all those replies.

I have the solution: I'll keep studying C++ as a hobby, while continuing my C# projects.


Define low level language. From my perspective, C++ is not a low level language, even C has a sufficiently nice set of abstractions on it that help to remove some of the more machine level concepts. If you really want to learn about low level programming you need to get into micro-architectures. Things like the propeller can be a great introduction to low level/embedded coding and are cheap enough and simple enough to get into on a budget.

As far as learning C++ goes, Telastyn's list of reasons are pretty much the main ones you should concern yourself with as a guide to determining when you should "switch" to C++. But I've got a few hints for you:
  • You'll never "switch" to another language. You may one day end up using one language more than another, but the more languages you know the more doors you open. Both for solving problems and for job opportunities.
  • Every language has a set of problems its good at solving, do not blind yourself to other languages just because you have a preference for one. This bites many a beginner on the butt many a time. If you need to ping a target and check the error result then you can do all that in a batch file, you don't have to write a C++ or C# application.
  • You don't have to abandon a language to learn another. You can learn two languages side by side, or practice your main language while you learn a secondary. In fact, this can be an easy way of learning the differences between two languages and how they apply their respective idioms. It can also help you in understanding how the "implementation" of something actually works.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX


#25 GrandMaster789   Members   -  Reputation: 147

Like
4Likes
Like

Posted 14 September 2012 - 04:03 AM

C++ allows for very detailed control over the operation of your programs. It provides you with numerous tools to express yourself in many paradigms; if you want you can mix various styles of coding in a single project. Don't underestimate the amount of stuff that is provided, and realise that many c++ features are really different approaches to doing things.

However, some of the coding style options that are provided are not exactly the safest way to program. The language generally requires you to know what you're doing and doesn't really do a lot of hand-holding. I guess the most obvious thing you'll notice when you come from a C# background is the manual, very explicit resource management. That and a relatively small standard library.

For me, the main reasons for choosing C++ are:
- Detailed, explicit control over your application
- Freedom of expression
- Large set of (domain-specific) libraries
- Code will compile to just about any platform
- Language will remain stable for many (~10) years

Reasons against:
- Complicated compilation/linking rules
- Difficult to read compilation error messages (and a steep learning curve because of it)
- Limited managed resource access (many ways to mess up, correct usage requires discipline)
- Smallish standard library (when compared to C# or Java)
- Slow to adapt to programming language trends

If you want to learn C++, might I suggest you don't bother with legacy stuff and jump straight to C++11. The improvements to the language are beneficial to beginners and veterans alike.

#26 swiftcoder   Senior Moderators   -  Reputation: 9636

Like
0Likes
Like

Posted 14 September 2012 - 05:31 AM

- Language will remain stable for many (~10) years

10 years ago we didn't even have standard-comformant compilers. And we still don't have a conformant C++11 implementation, to the best of my knowledge.

Not sure I'd call that 'stable' Posted Image

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#27 GrandMaster789   Members   -  Reputation: 147

Like
0Likes
Like

Posted 14 September 2012 - 05:48 AM


- Language will remain stable for many (~10) years

10 years ago we didn't even have standard-comformant compilers. And we still don't have a conformant C++11 implementation, to the best of my knowledge.

Not sure I'd call that 'stable' Posted Image


You're right about that, although I would argue that the *standard* didn't change for ~10 years. If you have C++ code that's 10 years old, it'll almost certainly still compile correctly to this day. If you have, say, Java code that's 10 years old, it probably won't work anymore.

The whole C++11 implementation stuff is a bit comparable to browser adoption of CSS, where the standard had been established for many years before any browser would correctly render it. At the moment there is no complete implementation of C++11, although for example the latest GCC and MSVC compilers do a pretty good job already.

Edited by GrandMaster789, 14 September 2012 - 06:16 AM.


#28 swiftcoder   Senior Moderators   -  Reputation: 9636

Like
0Likes
Like

Posted 14 September 2012 - 06:46 AM

If you have C++ code that's 10 years old, it'll almost certainly still compile correctly to this day. If you have, say, Java code that's 10 years old, it probably won't work anymore.

WTH do you get that idea?

The rate of code-rot in unmaintained C++ code bases is truly ridiculous, especially if you have any meaningful external dependencies. I'd say that 10 year old C++ code rarely still compiles - and when it does, it's often only with a legacy compiler (Visual Studio 6, how do I love thee? Let me count the ways...)

By comparison, all Java code from 10 years ago not only still compiles, but is still standard-conformant (because java actually had a consistent standard, well more than 10 years ago).

Edited by swiftcoder, 14 September 2012 - 06:47 AM.

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#29 Telastyn   Crossbones+   -  Reputation: 3724

Like
1Likes
Like

Posted 14 September 2012 - 07:03 AM

Detailed, explicit control over your application


Eh? You don't even know the size of your int's...

#30 GrandMaster789   Members   -  Reputation: 147

Like
1Likes
Like

Posted 14 September 2012 - 07:27 AM

I suppose a more detailed explanation is required here... it does highlight an issue I neglected to mention: because 10 years ago most compilers would not correctly implement C++, it's doubtful if code that worked 10 years ago would actually be compliant C++ (VC6 was notorious for this).

Recently I dusted off some of my own old code from back then and it worked perfectly. This is, of course, anecdotal evidence and probably not correct for all projects, but as the topic here is very subjective anyway I thought I'd share my personal experience.

I mentioned Java because I used to program with it 10 years ago, and back then it had a habit of deprecating all sorts of standard library functions. The language itself didn't change that much, true. I haven't had much experience with Java lately so my opinions on that language may be a bit dated.

#31 swiftcoder   Senior Moderators   -  Reputation: 9636

Like
1Likes
Like

Posted 14 September 2012 - 07:56 AM

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

Edited by swiftcoder, 14 September 2012 - 09:30 AM.

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#32 Hodgman   Moderators   -  Reputation: 27837

Like
0Likes
Like

Posted 14 September 2012 - 08:58 AM

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.

Edited by Hodgman, 14 September 2012 - 08:59 AM.


#33 Karsten_   Members   -  Reputation: 1498

Like
-3Likes
Like

Posted 14 September 2012 - 01:57 PM

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.

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


#34 Telastyn   Crossbones+   -  Reputation: 3724

Like
1Likes
Like

Posted 14 September 2012 - 02:01 PM

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.

#35 Karsten_   Members   -  Reputation: 1498

Like
-2Likes
Like

Posted 14 September 2012 - 02:40 PM

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.

Edited by Karsten_, 14 September 2012 - 02:42 PM.

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


#36 LordJulian   Members   -  Reputation: 151

Like
4Likes
Like

Posted 14 September 2012 - 02:49 PM


Detailed, explicit control over your application


Eh? You don't even know the size of your int's...

Sure we do, it is sizeof(int) :P

#37 LordJulian   Members   -  Reputation: 151

Like
1Likes
Like

Posted 14 September 2012 - 02:52 PM


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



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

#38 Shannon Barber   Moderators   -  Reputation: 1355

Like
0Likes
Like

Posted 14 September 2012 - 03:22 PM

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.

Edited by Shannon Barber, 14 September 2012 - 03:24 PM.

- 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

#39 Shannon Barber   Moderators   -  Reputation: 1355

Like
0Likes
Like

Posted 14 September 2012 - 03:27 PM

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

#40 Karsten_   Members   -  Reputation: 1498

Like
-3Likes
Like

Posted 14 September 2012 - 04:02 PM

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.

Edited by Karsten_, 14 September 2012 - 04:11 PM.

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS