FAQ Search
Memberlist Usergroups
Profile
  Forum Statistics Register
 Log in to check your private messages
Log in to check your private messages
Moonpod Homepage Starscape Information Mr. Robot Information Free Game Downloads Starscape Highscore Table
C++ Class use
Post new topic   Reply to topic    Discussion Pod Forum Index -> Independent Game Development View previous topic :: View next topic  
 Author
Message
BluePhoenix



Joined: 08 Jun 2004
Posts: 96
Location: Between Georgia and Cuba



PostPosted: Fri Jun 16, 2006 6:26 pm    Post subject: C++ Class use Reply with quote

I was wondering how much if at all you guys use C++'s OO features (especially classes). I'm curious to know how professional programmers have organized and used such features as I've not seen many good examples of it (I'm reasonably certain I'm the only one at my college within my major who even knows how to use classes and inheretance to a practical degree ~_~;; ). My particular interest is in integrating graphics engines with classes and what not.
Back to top
View user's profile AIM Address Yahoo Messenger
Poo Bear
Pod Team
Pod Team


Joined: 14 Oct 2002
Posts: 4121
Location: Sheffield, UK



PostPosted: Mon Jun 19, 2006 9:04 am    Post subject: Reply with quote

C++'s Object Orientated features allow you to better manage complexity and therefore are vitally important to our games as they easily hit 150-200 thousand lines of code and more. So it's pretty essential really, things like classes, inheritance, polymorphism, templates and higher level containers via the standard template library are all used. Be warned though, it's surprisingly easy to get into trouble using all the features i've just mentioned and I'd rather see simple, well written, well documented code than badly written or unnecessary OO code.

As well as the core OO ideas mentioned above a lot comes down to how they are actually used, these two books were important to me in this regard:

Design patterns - Gamma, Helm, Johnson, Vlissides
Ways of using classes to achieve a specific objective i.e. making new objects, hiding complex code behind a simple interface, etc.

Object Oriented Game Development - Julian Gold
Written by a lead programmer at Microsoft Games it shows the ideas from the previous book actually being put into practice.

My advice - always have one technical book by your bed that you are reading, you only learn the tip of the iceberg at school/college/uni. If necessary join a library Smile
Back to top
View user's profile Visit poster's website
Johnh



Joined: 06 Sep 2003
Posts: 160



PostPosted: Thu Jul 06, 2006 3:45 pm    Post subject: Reply with quote

I can't remember where I read this, so take it as a grain of salt, but:

The largest C program that a person can write and comprehend is 100 thousand lines. However, in C++ the largest program a single person can write and comprehend is 300 thousand lines.

Anyways, even if the numbers stated above are wrong, a program written well in C++ is easier to understand than a program written well in C. However, as Poo Bear mentioned, a program written well in C is much easier to understand than a program written poorly in C++.

OO principals make writing modular code easier since classes lend itself well to a module of code. This means that once you have a single class fully coded and tested, you no longer have to worry about errors originating from that code (of course, this presumes that you correctly tested all possible code paths in your class), no matter how you use the class.

Furthermore, use of classes and inheritance can mean that code reuse is up, and duplicate code is down.
Back to top
View user's profile
Poo Bear
Pod Team
Pod Team


Joined: 14 Oct 2002
Posts: 4121
Location: Sheffield, UK



PostPosted: Fri Jul 07, 2006 8:46 am    Post subject: Reply with quote

Object Orientation delivered via classes in C++ can actually fail to deliver modularity and reuse in large real world applications. I know they teach otherwise but a lot of people are starting to get a little disheartened with C++. The problem is to use a class you need to include the class header file everywhere it is used and doing that forms a very hard concrete dependency between them. If you aren't extremely careful every class has a spidersweb of dependcies reaching out into every other class (interestingly i've never seen a large application that avoided this ever). You cannot reuse something if it depends on 3 other classes which in turn depend on 2 classes each which in turn, etc, etc. Similarly, the more a class is dependant on the less modular and independent it is. Readability drops, compile times go up and maintainability gets very hard.

Another major OO feature of C++ is polymorphism and inheritance, yet again this can bring just as many problems as benefits. Once more you are increasing dependencies on other files. Plus you have to understand in detail how all the classes work further up the inheritance tree to stand a chance of calling the constructors and destructors in the right order. If you override a function then is it ok to ignore the base class implementation or should that be called straight away in the new function? You will almost definitely need a bolted on mechanism of identify object type (rtti is slow) so you can start casting things into more specific objects, lets hope you set all the object type values up correctly in the constructors.

Now, all these problems have been addressed via things like the STL, the boost libraries and better design methodologies (see the book "Design Patterns"). However, these are "add-ons", they aren't directly built into the language so different people pick and choose and compilers support some and not others. A bad situation.

Sorry to be doom and gloom, but you need to go into C++ with your eyes open, that language is long overdue for an overhaul if not a replacement (see the language "D"). The problem is it's so popular it is difficult to get the emomentum to move it forward or change to something better.
Back to top
View user's profile Visit poster's website
Johnh



Joined: 06 Sep 2003
Posts: 160



PostPosted: Tue Jul 11, 2006 12:09 am    Post subject: Reply with quote

Poo Bear wrote:
Object Orientation delivered via classes in C++ can actually fail to deliver modularity and reuse in large real world applications. I know they teach otherwise but a lot of people are starting to get a little disheartened with C++. The problem is to use a class you need to include the class header file everywhere it is used and doing that forms a very hard concrete dependency between them. If you aren't extremely careful every class has a spidersweb of dependcies reaching out into every other class (interestingly i've never seen a large application that avoided this ever). You cannot reuse something if it depends on 3 other classes which in turn depend on 2 classes each which in turn, etc, etc. Similarly, the more a class is dependant on the less modular and independent it is. Readability drops, compile times go up and maintainability gets very hard.

Another major OO feature of C++ is polymorphism and inheritance, yet again this can bring just as many problems as benefits. Once more you are increasing dependencies on other files. Plus you have to understand in detail how all the classes work further up the inheritance tree to stand a chance of calling the constructors and destructors in the right order. If you override a function then is it ok to ignore the base class implementation or should that be called straight away in the new function? You will almost definitely need a bolted on mechanism of identify object type (rtti is slow) so you can start casting things into more specific objects, lets hope you set all the object type values up correctly in the constructors.

Now, all these problems have been addressed via things like the STL, the boost libraries and better design methodologies (see the book "Design Patterns"). However, these are "add-ons", they aren't directly built into the language so different people pick and choose and compilers support some and not others. A bad situation.

Sorry to be doom and gloom, but you need to go into C++ with your eyes open, that language is long overdue for an overhaul if not a replacement (see the language "D"). The problem is it's so popular it is difficult to get the emomentum to move it forward or change to something better.


You mean... they lied to me? *sniffle* Crying or Very sad

I always thought that the professionals just designed the classes so well that the spiderweb of dependencies was much more manageable.

I don't know if I should be relieved because it means my design isn't flawed in that respect (or rather that the flaw is unavoidable), or if I should be frightened that there is no simple,elegant solution to that flaw 0_o.
Back to top
View user's profile
Poo Bear
Pod Team
Pod Team


Joined: 14 Oct 2002
Posts: 4121
Location: Sheffield, UK



PostPosted: Tue Jul 11, 2006 8:12 am    Post subject: Reply with quote

That's the problem, the "flaw" is indeed avoidable, but there isn't a single elegant solution, there are a number of different solutions and students usually don't get taught them because the language is so complex they spend all their time on the basics (which aren't very basic Smile ). It's not just a case of reading a book either, knowing which stl container fits your problem best or when to use a specific design pattern is hard.


It's not just me either, the site below contains a pod cast interview with the developer at www.positech.co.uk. It's a bit long and the interviewer keeps saying "awsome", but still. He talks a lot about pro-developers who you would think would be grade-A coders still using dodgy coding practices, throwing lots of code away and being unable to deliver anything on time (sounds like us Smile ). Part of the blame lies with the language I feel and part of it lies with management not understanding how software is put together or how scheduling works.
http://www.indiegamepod.com/
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Discussion Pod Forum Index -> Independent Game Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group