Question

So I'm making my first serious project.

Namespace structure:

  • Egg
    • Math
    • Physics
    • ...
    • Simulation

A header:

#ifndef EGG_PHYSICS_WORLD_HPP
#define EGG_PHYSICS_WORLD_HPP

namespace Egg {
namespace Physics {

class Body
{
public:
   Body();

   const Math::Vector2& GetPosition() const;

   /* ... */
};

} // namespace Physics
} // namespace Body

#endif // EGG_PHYSICS_WORLD_HPP

Questions:

  • Is it a sane organization overall?
  • Is it a good practice to create nested namespaces?
  • Is it OK to use a name that's not fully specified (eg. Math::Vector2) name instead of ::Egg::Math::Vector2 in ::Egg::Physics namespace?
  • If nested namespaces are overorganizing, is it OK to use a single namespace but still use a folder structure, eg. Egg::World located in "Egg/Physics/World.hpp"?
Was it helpful?

Solution

Yes, you are overorganizing. If it is application code, I would not use namespace at all, normally. If you move code to reusable library, wrap it to namespace then, but not before. Use class names which make sense without namespace.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top