开发者

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

开发者 https://www.devze.com 2022-12-16 03:32 出处:网络
I run code analysis on a project a开发者_高级运维nd I get a warning saying CA1020 : Microsoft.Design : Consider merging the types defined in {some namespace} with another namespace.{some namespace}

I run code analysis on a project a开发者_高级运维nd 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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消