Jump to content
  • Advertisement
Sign in to follow this  

Optimizing my c++ code

This topic is 3440 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I though it was time to optimize my code/make good c++ code.. Right now I think I am not really doing object oriented programming... my code is messy and noobish. I use globals a lot, I use structures and any efficient measure for code you can think off I probably don't use.. Could anyone give me some tips/point me to an article on two on how to make good code? Something that caught my attention a while ago that several programs from books and tutorials I came a cross had everything handled in complex classes, classes kept in header files that were accesed in source files. I don't know how to go about or where to start changing my code to this style, it looked really organized and 'efficient'. Any info on the subject would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Writing good code has little to do with "optimizing" or "efficiency" - unless you are talking about programmer efficiency.

The first step is typically to break your code into smaller chunks. This may help.

Share this post


Link to post
Share on other sites
Oh I already read that article and did the splitting into headers and source files though I am not sure I am doing a good job when it comes to what functions go in what files. I am also trying to get rid of my global variables.

Share this post


Link to post
Share on other sites
Quote:
Writing good code has little to do with "optimizing" or "efficiency"

More like, writing good code is broad area with a few different measures. In my opinion (i.e. I agree with rip-off) the first area to work on would be code layout, structure and naming . But optimization and efficiency in terms of algorithm choice, and data management are very important in certain areas of games programming at certain levels (generally professional level, or "hardcore" projects).

Share this post


Link to post
Share on other sites
I would recommend Effective C++ over Code Complete. I liked the concrete examples Effective C++ was able to give, and the lay out was very nice. I would also recommend reading Guru of The Week as a free resource.

Share this post


Link to post
Share on other sites
Quote:
Original post by Antonym
Oh I already read that article and did the splitting into headers and source files though I am not sure I am doing a good job when it comes to what functions go in what files. I am also trying to get rid of my global variables.


Generally you create a header/source pair for every class you write(and the majority of your code should be in classes), the rest of the functions would usually be grouped in files by functionality. I don't know what your project is, but say all your set-up/initialization functions would be in one, possibly along with clean up, all of your asset/file loading could go in one, but liek I said, these would generally be in classes.

The only "loose" functions you should have would be utility functions in which there aren't enough related ones to form a utility class.


also, when you're talking about optimization, if you remember anything, remember this... 20/80. 20% of your code will be run 80% of the time, and that is a proven fact. So although you should generally write code with proformance in mind, figure out the code that gets run the most, and that is what you should optimize first

Share this post


Link to post
Share on other sites
Quote:
Original post by Treb
I would recommend Effective C++ over Code Complete. I liked the concrete examples Effective C++ was able to give, and the lay out was very nice. I would also recommend reading Guru of The Week as a free resource.


Effective C++ points out common mistakes , it does not go too deep into organization, optimization, modularity, cohesion etc. Code Complete teaches you how to write reliable, clear code. Effectiv C++ complements by going deeper into the syntatical correctness.

Share this post


Link to post
Share on other sites
Hi,

if you want to use good object oriented solutions I suggest you to read this book. The book is not for beginners so, before buying, consider if you would be able to understand it.

Another good solution would be to study on good source code or to work with experienced programmers.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!