How do you manage multiple builds sharing the same code?

Started by
21 comments, last by JasonBlochowiak 17 years, 5 months ago
Hello everyone, I have been playing around with different ways of seperating my two build. Both share alot of code and both need to have some parts synced or they won't be able to communicate. I tried two things and I would like to know which one you find the best: 1. Keeping both builds in the same project, and putting two preprocessor defines. One each for Build1 and Build2. This actually works great, but the code looks like sh*t. Very cluttered by all the ifdefs. 2. Two different projects and keeping both updated by the changes made to them. This way it looks cleaner (IMO, of course) but on the other hand mistakes are more common when you forget to copy/paste over the updates from the other project. I prefer number 2 myself, because then I can customize both projects perfectly, deleting the project files/code I don't need, instead of having to ifdef them out. Any thoughts?
Advertisement
3. Separate the common code into it's own project, a library of sorts that the first two projects depend on.
Thanks for your suggestion but that is not practical in my case for a number of reasons, which is why I asked: Which of the two would you prefer?
I would refactor those reasons and still go for number 3 :)

If I would really have to pick between the first two, then I'd probably pick number one to avoid the whole cut-and-paste desynchonisation mess. I would postulate that ugly code that always works is better than beautiful code that only works 50% of the time.
Definately 1 IMO. Code doesn't have to be pretty to be functional. Managing 2 projects would get real old real fast.
Tough question. If your two builds differ only by a particular set of files, go with option 2. If you need to make changes here and there and everywhere defines are the better option of the two you've presented.

The "right" way (as mentioned) to do this is to put shared code into libraries. Where possible, non-shared code should share a common set of interface files, but separate implementation files.
You could create an abstraction layer that gave each set of code a common interface. And then put #defines around the portion of code that implements the abstraction layer. Sort of like abstracting out a renderer or file system access.
-----------------------------------Indium Studios, Inc.
Quote:Original post by DrEvil
Definately 1 IMO. Code doesn't have to be pretty to be functional. Managing 2 projects would get real old real fast.


Thanks.

Quote:Original post by Anonymous Poster
Tough question. If your two builds differ only by a particular set of files, go with option 2. If you need to make changes here and there and everywhere defines are the better option of the two you've presented.

The "right" way (as mentioned) to do this is to put shared code into libraries. Where possible, non-shared code should share a common set of interface files, but separate implementation files.


Aye, I would had used a shared library if the code wasn't so much dependant on different parts. It would require alot of recoding and that's alot of work.

Quote:Original post by jkleinecke
You could create an abstraction layer that gave each set of code a common interface. And then put #defines around the portion of code that implements the abstraction layer. Sort of like abstracting out a renderer or file system access.


I made two abstraction layers for the renderer and audio system, but I'm not sure how to handle the rest.

Your opinions are greatly appreciated and thanks again for the suggestions.
After some thinking, I have decided to go with option 2. I just couldn't get my head around all those ifdefs, and I just realized the differences are mostly in a particular set of files, and some random ones.

Thanks again for your opinions.
I would use number 3 as suggested above but as an alternative, I would create two project/solution files that only compiles/includes the files needed for the build.

Steven Yau
[Blog] [Portfolio]

This topic is closed to new replies.

Advertisement