Opinion question on the best method to structure a solution

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CProgrammer80
    New Member
    • Feb 2008
    • 2

    Opinion question on the best method to structure a solution

    I am compiling 4 different programs, each using a lot of the same core functions and files. One of the programs requires access to a large third party library, the others do not.

    I have created an "options" structure suitable for all 4 programs. The way the options structure is filled out however can differ depending on the program which is to be used. Most of it is trivial stuff... "do I write to stdout?", etc. However, one of the programs, in the options function, may attempt to access those functions calling the large third party libraries if some information is not available. Moreover, it must do this before the rest of the options can be processed, and its purpose is intricately tied to task of options processing.

    How would you set up the source code in files suitable for this? Here are some choices as I see them:

    1. Use one options.cpp file, and link everyone against the large library.
    2. Use one options.cpp file, and move the offending line of code elsewhere.
    3. Tie the options processing, usage statements, etc., into the same file containing the main() for each program.
    4. Create different .cpp files for the filling out of options data (p1-options.cpp, p2-options.cpp, ...) where each program links only to the instructions for options filling that it needs.
    5. Create one options.cpp file, with #ifdefs for each program. Use makefile trickery to compile different options object files (p1-options.o, p2-options.o, ...) all from the same one source file.

    I like option 5 the best, which is to say I don't like it much, but I have yet to come up with a better thought as to how to do it. Hence the request for suggestions/comments. As per my thoughts on each:

    1. Unnecessary Bloat
    2. Not a reliable solution for the future
    3. Creates too much code in the files containing main()
    4. Not very elegant, and a larger traversal should an option need to be changed. Basically more clunky than (5).
    5. Still clunky

    Thanks!
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I like option 6 or 7:

    6) each function is in it's own .cpp file. Just add the .cpp files as needed to your project. Remeber, adding a .cpp file to a project does not require that you make a copy. All projects can use the exact single .cpp file.

    7) group commonly accessed functions into a library that is built as a separate project. Add the library as necessary to projects that need the functions.


    You should not have an "options" file unless you are preparing code for different platforms, like Unix. Linus, Windoes, AIX, etc.

    Your "options" file is kinda like an uber-makefile and I don't think you need the complexity.

    Comment

    Working...