Jump to content
  • Advertisement
Sign in to follow this  
TerrorFLOP

Coding Large Projects

This topic is 4163 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

Just a quick question here... In the past, I've always written small, highly modularized code, usually packaged as DLL's, which I can then link dynamically together during runtime. However, my DX9Graphics tools DLL is starting to bulge... BADLY! I've always tried to write code in small chunks, so rather than have a large single source file, I've opted for multiple source files to be complied and linked during buildtime. The question is this, should I also use multiple header files too, that correspond to their source file counterparts? Or should I simply use one large, (and it's going to be quite large!) header file that's common to all source files? So I just need to know, what is the best coding practise with regards to organising a large VCPP 2005 project?

Share this post


Link to post
Share on other sites
Advertisement
Well my last project ended up at around 50,000 lines give or take, so I had to deal with code organization early on.

Every module gets its own header and source file. The header file has no includes. The source file includes a precompiled header file. In the precompiled header file I include every other header file I need - external and local. The local header files are included in the order that they depend on each other, and in the case of cross-dependencies I would put a forward declaration of the object beforehand. With the precompiled header file the code compiled reasonably fast for 100+ header/source files.

Now I know that's not entirely efficient, but a precompiled header file reduced compile time soo much for 120-odd header/soruce files. Plus I had wayyy too many linker problems doing it any other way. Another benefit is that anytime you need to use an object you don't have to scroll up in the source and include the file --- its already included if its in the precompiled header.

Besides that keep your code organized with good documentation and a consistent style that works for you. Good luck.

Share this post


Link to post
Share on other sites
Personally I'd keep a single header and implementation file for each class, and I'd try to keep dependencies to a minimum. Which usually results in about an equal number of .h and .cpp files. Haven't had problems with that approach so far.


A while ago I found an article that contained some compile tricks to keep compile times and binary filesizes down, with some interesting results. I don't have the link here at home, but an interesting approach was including all .cpp files in a single .cpp file, so the linking process was greatly simplified. It sounds hacky, and I haven't tried it myself yet, but at least in the tests the author did, it greatly reduced the amount of includes and cut down on compile time and binary size pretty much, so I think it's interesting enough to at least know about. :)

Share this post


Link to post
Share on other sites
Thx guys!

Some interesting ideas there. Well I'll probably continue with the multiple source, single header file approach for now. But I guess in time I'll probably revert to the standard approach of using a header/source file pair for individual classes, as my module grows.

Thx again.

Share this post


Link to post
Share on other sites
I usually make it as messy as possible so if someone ever steals my code they wont be able to understand it! Moo ha ha ha! Or maybe I'm just lazy? You pick :D

Nah, I do the single file + header per class as well, and I also use lots of little folders in my IDE so I can find exactly what I'm looking for. Also, spending an extra minute writing out a lengthy comment for each function is very helpful.

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!