Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the consequences of having (too) many namespaces?

I run code analysis on a project and I get a warning saying

CA1020 : Microsoft.Design : Consider merging the types defined in {some namespace} with another namespace. {some namespace}

Why do I get this? Is there a negative implication of having too many namespaces?

like image 632
Corpsekicker Avatar asked Jan 14 '10 05:01

Corpsekicker


2 Answers

I believe the main reason is discoverability and believe that plays a large part in the successful support and maintenance of your code. If it's easier to discover it should be easier to maintain.

Here's the a quote from MSDN.

Namespaces should contain types that are used together in most scenarios. When their applications are mutually exclusive, types should be located in separate namespaces. Careful namespace organization can also be helpful because it increases the discoverability of a feature. By examining the namespace hierarchy, library consumers should be able to locate the types that implement a feature

like image 68
Kane Avatar answered Oct 01 '22 01:10

Kane


There are no real negative implications at runtime, in terms of increased memory or execution times. Also, namespaces are not like IP addresses, which have a fixed pool and can eventually run out.

Namespaces are basically a naming convention to help you group related things together. The CA error is suggesting that too many small namespaces may make your code harder for other people to use.

like image 31
IanRae Avatar answered Oct 01 '22 01:10

IanRae