I need help with structuring, really bad!

Started by
8 comments, last by Wilhelm van Huyssteen 11 years, 6 months ago
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 smile.png

I'm a game programmer and computer science ninja !

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here !

Advertisement
I have no book recommendations, but may I suggest another approach: code, code, and code again. Eventually you will see design patterns appear and you'll learn to work with them. If something doesn't make sense, try and change it, even if it means a rewrite. I never found reading about programming a particularly effective way to learn, to me nothing beats practical experience. This is a subjective opinion, YMMV *casts downvote shield*

One thing about OOP is that it may be approached with different points of view depending on what you try to achieve (or sometimes you might think of it differently to someone else just because of the way you think). That's why there are so many "patterns" out there, each with their own strengths and weaknesses (and are sometimes equivalent if you are consistent, and so are up to taste). So don't get too hung up on one particular way of doing things, use whatever works for your project and what you find attractive.

What problems did you run into? Things such as separating logic and graphics, that kind of stuff? Or how to split code files sensibly to maximize reusability? Or how to define proper interfaces for your classes? ...

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

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 :)

I'm a game programmer and computer science ninja !

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here !


Books about linear algebra

Try Khan Academy.


Books about C++

Check out these recommendations.


Books about writing cleaner code

Code Complete is excellent and I'd highly recommend it to anyone and everyone after getting a solid foundation 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.


Books about object oriented design

Try these articles on OO design principles. 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 practice, practice and more practice. 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 Project Euler or give Code Kata 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! cool.png

- Jason Astle-Adams


Figuring out what should be objects, what they should inherit from, Especially Reusable code, etc.


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/

[quote name='superman3275' timestamp='1349064095' post='4985635']
Figuring out what should be objects, what they should inherit from, Especially Reusable code, etc.


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.altdevblo...ogramming-in-c/
[/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.

I gets all your texture budgets!

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.

•Books about writing cleaner code.


Take a look at this one: http://www.amazon.co...cm_cr_pr_sims_t

[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.
http://www.e-reading.org.ua/bookreader.php/134601/Clean_Code_-_A_Handbook_of_Agile_Software_Craftsmanship.pdf
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.

This topic is closed to new replies.

Advertisement