Advertisement

Big cpp files

Started by March 23, 2001 03:31 PM
3 comments, last by Zeblar Nagrim 23 years, 10 months ago
How many lines is to much for a cpp file? Is it OK (regular) to split up a big cpp.file in smaller ones? Let´s say I have a class called "Main". The "main.cpp" have 4000 lines. It takes 10 seconds to hit the tiny scrollbar button with the cursor... Now I create a new file called "graphic.cpp" and put in every function body that fit into this category. Sounds fine? Zeblar Nagrim, Lord of Chaos
There is no set amount that is "too much". Odds are if you have a class that contains 4000 lines, then you need to rethink your class. You can probably split that class into multiple smaller classes.

For instance, you were talking about putting the graphics functions into another .cpp file. It''s generally a bad idea to mix graphics and logic in the same class anyways so you might want to consider creating a whole seperate class for the graphics functions.


- Houdini
- Houdini
Advertisement
Yes, in many cases that's the approach you'll want to take. For example, my isometric engine is over 30 cpp files and headers (not including the ones other people wrote). See this tutorial it gives you a decent multiple file model to work off of. I personally give each cpp file its own header, and include that header in global.h though.

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP's Invasive Production Activation Technology!
http://www.gdarchive.net/druidgames/

Edited by - Null and Void on March 23, 2001 5:01:57 PM
It is good to chop up your programs aka modules so it is eaiser to debug, clean and change. When i made Direct X projects i most of the time put my gobals and includes in one header and put the main code in a cpp file.
As an added bonus, if you split things up correctly, changing 1 .h file won''t mean you have to recompile the entire project! Only the files that actually include that specific h file.

I know this won''t mean much at first or for those with super duper computers, but for older computers working on big projects (read: any game above Tetris in complexity), recompiling the whole thing can take almost a minute... think about that... a minute of thumb twiddling.... every time you change 1 little piece of code....

This topic is closed to new replies.

Advertisement