I am used deep nested namespaces and to also have my folder structure according to the them (For example "Core/System", "Core/Graphics/Textures"...). Now I read that in C++, nesting namespaces is not encouraged and is only used to prevent nameclashes.
Is that how you do it in C++? Does a deep folder structure make sense for a C++ project, or is a shallow structure considered standard?
It's a matter of style. I generally prefer having only one level of namespaces, which has been enough in all the projects I have worked on (some involving hundreds of thousands of lines of code).
How to include correctly? Observer pattern example
to illustrate my problem, let's say I have an Observer/Observable pattern implemented:
Now for the Observable can:
#include "Message.h" of
declares "class Message;"
The Observer can:
#include "Observable.h", and implicitly know about the Message class as well, if Observable uses Method 1
#include "Observable.h", #include "Message.h", thanks to header guards this works.
#include "Observable.h" and declare "class Message;"
What's the "right" way to do it, or is there none?
You should generally prefer a forward declaration if that's enough (i.e., if you are only going to declare pointers or references to the class), especially in header files. That way compiling a module won't require reading an extra header file, and a change in the header file will trigger recompilation of fewer modules.
I don't know if it is a religious topic, but some sources say nested headers are baaaad. are they?
I saw something like:
every file included globals.h, is this a common practice or is it stupid?
That's a bad idea. It makes everything depend on everything else. If you made a change in a header file the whole code would need to be recompiled, whether it has anything to do with the change or not. It
You should only include the header files you use. That way you can also identify groups of modules that form sefl-contained units and perhaps promote them to a libraries, which is a useful way to organize code and encourage code reuse.