Sign in to follow this  
superman3275

I need help with structuring, really bad!

Recommended Posts

I've recently ran into a LOT of problems with how I structure my code. I just don't have a very good idea about object oriented properties/inheritance/encapsulation. If anyone can recommend some books, free pdf's, pod-casts video tutorials, anything about structuring object oriented systems(Especially specifically involving game development). I would like to do a lot of reading on this(2+ hours a day) so I can become a better programming. All recommendations are helpful [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites
Figuring out what should be objects, what they should inherit from, Especially Reusable code, etc. I more or less need something to help me understand how I should apply this to video game programming. Also, I'm refining my list:
•Books about linear algebra
•Books about C++
•Books about graphics programming
•Books about object oriented design
•Books about writing cleaner code.
Please Give me everything you got, especially about linear algebra :)

Share this post


Link to post
Share on other sites
[quote name='superman3275' timestamp='1349064095' post='4985635']
Books about linear algebra
[/quote]
Try [url="http://www.khanacademy.org/"]Khan Academy[/url].

[quote name='superman3275' timestamp='1349064095' post='4985635']
Books about C++
[/quote]
Check out [url="http://clicktobegin.net/programming/intermediate-to-advanced-cpp/"]these recommendations[/url].

[quote name='superman3275' timestamp='1349064095' post='4985635']
Books about writing cleaner code
[/quote]
[url="http://www.amazon.com/gp/product/0735619670/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0735619670&linkCode=as2&tag=clic033-20"]Code Complete[/url] is excellent and I'd highly recommend it to anyone and everyone [i]after getting a solid foundation[/i] in the basics of your chosen programming language. This is a more advanced book, and although it's very clear and well written many of the suggestions and examples simply won't make sense without a certain base level of knowledge.

[quote name='superman3275' timestamp='1349064095' post='4985635']
Books about object oriented design
[/quote]
Try these articles on [url="http://www.objectmentor.com/omSolutions/oops_what.html"]OO design principles[/url]. Again, a lot of this may not make a lot of sense until you're able to actually put it into practice, and beginners often have trouble understanding some of the potential problems or pitfalls of poor design until they have personally experienced the problems that can arise.


You didn't have it on your list, but there may also be some value in reading about "design patterns".


However, I agree with the above suggestion from Bacterius -- a good book or reference material is great -- especially to introduce you to completely new or different ideas -- but to really get a good handle on programming you need [i]practice, practice and more practice[/i]. There is no replacement for real-world experience, and they say that to really master a craft you need 10,000 hours of experience. I think there's real value (for most people -- different people learn differently) in reading good books, but you absolutely need to keep writing code as well.


If you need more problems to practice your programming you could try some exercises from [url="http://projecteuler.net/"]Project Euler[/url] or give [url="http://codekata.pragprog.com/"]Code Kata[/url] a try, or simply continue to pick progressively more complicated games or other programs to attempt. I noticed you also spent quite a bit of time and effort improving, cleaning up and adding polish to your first game -- continue to do that, as it's a great learning experience and also establishes a good work-ethic of sticking with your software for the boring "finishing up" tasks once all of the interesting problems have already been solved.


Program structure in particular can be difficult for a beginner to come to grips with, and you really need to learn it through trial-and-error and lots of (potentially messy) experience. Just keep writing software in any way you're able to get it to work, and you'll gradually begin to notice patterns of what works well and what causes problems and needs to be avoided.

Hope that helps! [img]http://public.gamedev.net//public/style_emoticons/default/cool.png[/img]

Share this post


Link to post
Share on other sites
[quote name='superman3275' timestamp='1349064095' post='4985635']
Figuring out what should be objects, what they should inherit from, Especially Reusable code, etc.
[/quote]

Code reusability != inheritance.

Nor does it really necessarily have anything to do with object oriented programming. There are design techniques you can apply (composition, inheritance, etc.) to achieve code reuse, but you can also get a lot of code reuse if you write in a somewhat functional style. Another way to put it: Try to move as much as code as you can into pure functions/methods. For example, you could write your physics, general math, and collision code as a collection of simple functions, then piece them together however you need. You don't need to worry about shared state as much and it makes your code easier to test. I would also argue that it makes managing the complexity (of games) much easier.

Neither OO nor functional programming are silver bullets, in my opinion. In my (limited) experience with writing game code, it seems that a balance between the two approaches is very nice. It depends on what type of component you're trying to build--"best tool for the job" and all that. =)

For reference, there's a nice blog post about functional programming written by John Carmack: http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/

Share this post


Link to post
Share on other sites
[quote name='thok' timestamp='1349100536' post='4985753']
[quote name='superman3275' timestamp='1349064095' post='4985635']
Figuring out what should be objects, what they should inherit from, Especially Reusable code, etc.
[/quote]

Code reusability != inheritance.

Nor does it really necessarily have anything to do with object oriented programming. There are design techniques you can apply (composition, inheritance, etc.) to achieve code reuse, but you can also get a lot of code reuse if you write in a somewhat functional style. Another way to put it: Try to move as much as code as you can into pure functions/methods. For example, you could write your physics, general math, and collision code as a collection of simple functions, then piece them together however you need. You don't need to worry about shared state as much and it makes your code easier to test. I would also argue that it makes managing the complexity (of games) much easier.

Neither OO nor functional programming are silver bullets, in my opinion. In my (limited) experience with writing game code, it seems that a balance between the two approaches is very nice. It depends on what type of component you're trying to build--"best tool for the job" and all that. =)

For reference, there's a nice blog post about functional programming written by John Carmack: [url="http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/"]http://www.altdevblo...ogramming-in-c/[/url]
[/quote]

I use the same approach for most of my game code, trying to strike a balance between OOP, DOP and functional programming based on where each paradigm makes sense.
My math library which I've developed over the years is written using a completely functional approach for example as this provides a more natural approach to 'doing math' with a very clean and re-usable structure, while systems which have to process a lot of data will use a data-oriented approach, just to give an example.

Share this post


Link to post
Share on other sites
When I first started programing (not too long ago) I found myself in a similar boat. The syntax of the language made sense, but I couldn't wrap my head around what code to write where, when to use composition, when to use an interface, when to use inheritance, how to compartmentalize, etc. I didn't even know where to begin to start learning through trial and error. I found "Head First Design Patterns at Barnes and Noble, and it did a very good job of explaining design patterns, along with good OOP principles and concepts. It is writen with Java examples for code, but the patterns and concepts it goes into are univerally applicable. While everyone's learning styles are different, I found this book to be exceptionally helpful.

Share this post


Link to post
Share on other sites
[quote name='superman3275' timestamp='1349064095' post='4985635']
•Books about writing cleaner code.
[/quote]

Take a look at this one: [url="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/ref=cm_cr_pr_sims_t"]http://www.amazon.co...cm_cr_pr_sims_t[/url]

[EDIT]
I found the book free online and want to assume this is a legit site? (I just Googled the book name and it was the second link). If not I am deeply sorry and appologize. You should buy the book either way as it's a great read.
[url="http://www.e-reading.org.ua/bookreader.php/134601/Clean_Code_-_A_Handbook_of_Agile_Software_Craftsmanship.pdf"]http://www.e-reading.org.ua/bookreader.php/134601/Clean_Code_-_A_Handbook_of_Agile_Software_Craftsmanship.pdf[/url] Edited by UltimaX

Share this post


Link to post
Share on other sites
In VB we have #region "Name Here" #End Region to help organize the code. I recomend you write it all down on paper and organize it there first. Once you start to code sometimes it becomes a giant mess unless you plan it out on paper first. Hope that helps.

Share this post


Link to post
Share on other sites
Like the first reply stated. Just keep coding and you will see good patterns emerge.

Write the dam application and then you will spot the parts that you can generalize and move up the class hierarchy for reuse later. Don't even create an hierarchy until you find clear examples of duplication in your code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this