This is a convenient agreement for many projects, and some of them support or expect.
However, this is not a complete story. Although this is a good default, I donβt think it should be considered untouchable best practice, because there are some circumstances that can motivate things to do differently. Additional factors to consider include:
- The unnecessary propagation of a namespace and the deeply nested hierarchy namespace can be a pain for users of your types. In a large library, you may want to start organizing source code files in a folder before you feel the need to impose multiple namespaces on clients.
- In this regard, the hierarchy namespace in .NET should work so that dependencies between types pass from the child namespace to the parent, and not vice versa. This is not always a natural way to organize source code into folders / directories. For example, one is often seen by people creating namespaces such as MyNamespace.Foo.Common which are used both by type in MyNamespace.Foo.Bar1 and in MyNamespace.Foo.Bar2. This seems reasonable for them at the source level of organization of the code, but it violates the dependence of the namespace conventions.
- Sometimes you can provide additional functionality by adding some types to the library namespace distributing an additional assembly instead of completely freeing up a new version of the full assembly library. It will probably be more convenient to store the source code files for the corresponding assemblies separated from each other in the repository, rather than storing them together to save all types for the namespace in the same folder.
In short, I would say, following normal practice, if you have no good reason for this. But don't let this hold you back if you have a good reason to use the fact that namespaces can provide groupings of types that are completely orthogonal to their grouping into deployable assemblies and the source code that creates them.
source share