I just have a few general questions about keeping code clean and readable.
1) Should functions have separate files from main (prototypes and initialization) ? (the functions are long)
2) If functions do have separate files, in Main do I include the function prototypes or the function initializations?
3) Are global variables in main shared across all files in the project? If not, how would I make it so the variable has access by all files?
4) If I include functions, when I use #include do I keep the function file names in <> or ""? When would I use each one?
5) When including a function, do I just include its name, or its full address? (I am using Code Blocks). For example, if I am including a function file called calculate.hpp, would I do #include "calculate.hpp" or #include "Users\Me\My Documents\calculate.hpp"?
Lots of questions!
Simplistically speaking:
If “the functions are long”, consider how you can shorten them. Since you ask about keeping code clean, I recommend Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin, which talks about this at length.
You should only ever
#includeheader files.Global variables should be the exception rather than the rule. However, see my earlier point about declaration and definition.
You’re
#include-ing a whole file, not just a function.<>for system-wide headers, such as those in the standard library""for local headers, such as your owncalculate.hpp.Use relative paths (with forward-slashes where necessary), never absolute paths. Consider what happens when someone else tries to build your code.
I recommend checking out some open-source C++ projects on SourceForge or GitHub to see how they’re laid-out.