C vs C++ Programming for Games

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

C vs C++ Programming for Games

Postby DinkyDyeAussie » Tue Nov 04, 2014 3:12 pm

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

Postby jarod42 » Mon Nov 10, 2014 1:27 am

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

Postby Kyran » Tue Nov 11, 2014 3:18 pm

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

Postby DinkyDyeAussie » Sun Nov 16, 2014 2:55 pm

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

Postby Kyran » Mon Nov 17, 2014 7:15 am

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

Who is online

Users browsing this forum: No registered users and 2 guests