The first language that I truly learned was Java. In it, it is very syntactically easy to nest classes in an essentially arbitrarily complex package hierarchy, which keeps the code organized. It is easy because the syntactic clutter of a deeply nested hierarchy is all placed neatly at the top of the file with import and package declarations, and then classes are referenced solely by their primary name and nothing else in the code body.
In C++, this is not the case. There is no package declaration for a file, instead keeping the namespace name visible in all references to that namespace's contents is preferred. This is fine for only lightly nested namespaces (e.g.
std::chrono), but becomes very cumbersome very quickly if one tries java-style package nesting (e.g.
game_name::server::world::actor::messages::ChatMessage). Of course, one can add
using namespace declarations in addition to
#include, but this is a form of code duplication and feels about as cluttered. It also is a horrific idea for header code (which is often non-trivial, such as in the case of templates).
In C++, how can I allow for the powerful organization found with deeply nested namespaces, but without introducing non-trivial syntactic clutter?
The best idea that I have for this is to keep most to all of my program's code in a few simple namespaces (e.g.
game::detail), but this creates an entirely new issue where there are two separate hierarchies — one for namespaces, and another for the file system.