C vs C++ Programming for Games

Post Reply
User avatar
DinkyDyeAussie
Posts: 260
Joined: Fri Feb 10, 2012 10:39 am
Location: Australia

C vs C++ Programming for Games

Post by DinkyDyeAussie »

I know we've all debated the relevancy of C vs C++ programming for stratagus, and other commercial/legacy engines. I've been doing alot of thinking about what language I should learn (besides lua which is friggin easy and awesome). So far I love C the most. I am still not very versed in it but have been trying to learn it more.

There are alot of [tutorial] websites and books saying that learning C is bad if you intend to learn C++, as you have to "inlearn" C in order to learn C++ - I think that this statement is false, as C is C++'s foundation. I've got tutorials from youtube on game engine (DirectX/OpenGL) programming, and a tutorial series from Lynda.com on the C/C++ language, but I have yet to watch them all, which I intend to do.

I did some java tutorials too, and followed one guys youtube channel and made a side scrolller game which was fun, but Java just doesn't give me the same buzz as C.

So the reason I am saying all this is - if we intend on doing a full on refresh to the stratagus engine using C++, how much C++ will we be using to create it? Will it just be classes, pointers and some references? Or will we go full hog and use the heavyweight templates and explicit memory management features including 'new' and 'delete' keywords which need to be used carefully....

I'm not an expert, but I do enjoy programmng in C, as it is a much more straight forward language, and structs in C are like classes in C++, but they just look better than classes...

This whole thing is probably very incoherent to read, but I just wanted to ask these questions.
User avatar
jarod42
Posts: 101
Joined: Fri Jan 20, 2012 7:43 pm

Re: C vs C++ Programming for Games

Post by jarod42 »

My though:

It is true that C and C++ are different languages, but they share a lot ( :-/ also the bad things ).
Replacing malloc/free by new/delete is not enough to pass from one language to the other.

The good thing is that they understand better pointer.
The "bad" fact about learning C before C++ is that most people write (only) C in C++ and use mostly "C-spirit" than "C++-spirtit". For example, the usage of reference, std::vector, std::string, smart pointer to replace some of these pointer is not adopted enough by C programmer.
Due to most C tutorial, I think, I find that C programmer tends to reinvent the wheel instead of using standard functions.

C++ has RAII (http://en.wikipedia.org/wiki/Resource_A ... ialization) that allows to write cleaner code and safer code.
And since C++11, we may entirely avoid new and delete keyword (thanks to std::unique_ptr).

Template is mostly used for containers (std::vector) and some generic algorithm (std::sort).

C is better to expose as DLL (and C++ has extern "C" for that).
User avatar
Kyran
Posts: 499
Joined: Sat Dec 31, 2011 5:19 pm
Location: Australia
Contact:

Re: C vs C++ Programming for Games

Post by Kyran »

Come on Skype, Dinky.
04:27 jim4 why haven't you added wc1 support? this project sucks. i'm only going to use freecraft
05:06 jim4 finished wc1 support yet? i've been waiting for 6 years
05:10 jim4 new things scare me
User avatar
DinkyDyeAussie
Posts: 260
Joined: Fri Feb 10, 2012 10:39 am
Location: Australia

Re: C vs C++ Programming for Games

Post by DinkyDyeAussie »

One day I will Kyran. I would really like somebody to explain all the things of C++ as I appreciate the language, but when it comes to writing my own code in stratagus or from scratch, I am bewildered.

I could get on Skype tomorrow - if anyone's gonna be on???
User avatar
Kyran
Posts: 499
Joined: Sat Dec 31, 2011 5:19 pm
Location: Australia
Contact:

Re: C vs C++ Programming for Games

Post by Kyran »

I'll be away for a few days. We're generally on between 20-22.
04:27 jim4 why haven't you added wc1 support? this project sucks. i'm only going to use freecraft
05:06 jim4 finished wc1 support yet? i've been waiting for 6 years
05:10 jim4 new things scare me
Post Reply