34 votes

C# namespace and class naming convention for libraries

There is a nice document that contains a lot of rules that you should follow to be in line with Microsoft: Framework Design Guidelines. One thing that you should change: Do not name classes as their ...
nvoigt's user avatar
  • 7,727
12 votes
Accepted

Importing namespaces inside another namespace

No, you should definetely not abandom namespaces! Instead, you should organize your code better, and maybe check your architecture again. First, you should not use using namespace MyLibrary::...
BЈовић's user avatar
12 votes
Accepted

Same class and namespace name

You're right that you shouldn't name the namespace the same as a type it contains. I think there are several approaches you can use: Pluralize: Model.DataSources.DataSource This works especially well ...
svick's user avatar
  • 10k
12 votes
Accepted

C# namespace and class naming convention for libraries

It's very difficult to determine how effective your naming strategy is in isolation from the rest of your code. The namespace should give some idea where it fits in the broad structure of your ...
richzilla's user avatar
  • 1,103
10 votes

C++ namespace name isolation

Your approach is not technically wrong (except a minor detail, see footnote) but it goes against established usage patterns and obfuscates code. I.e. it lowers readability and increases the likelihood ...
besc's user avatar
  • 1,153
9 votes
Accepted

C# Names of Namespaces with version suffix

When the documents mention second-level, they're referring to the section of the namespace indicated as (<Product>|<Technology>). The product or technology should be version independent. ...
Neil's user avatar
  • 22.7k
9 votes
Accepted

Am I using namespaces wrong?

Am I using namespaces wrong? Wrongly. It's an adverb. And the answer is probably. In use cases, which would you prefer? There are several reasonable tests. Is one easier to read, easier to say, ...
Useless's user avatar
  • 12.6k
9 votes
Accepted

Are namespace constructs like 'using std::string' unacceptable also in .cpp files?

using directives are certainly acceptable in *.cpp files when C++ authorities like Herb Sutter and Bjarne Stroustrup explicitly say so in their published Core Guidelines: Use using namespace ...
Christian Hackl's user avatar
8 votes

C++ namespace name isolation

Looks like a wrong approach, for several reasons: The things that you don't want to be "visible" to outside, should not go into headers. Instead they go into anonymous namespace in the source file. ...
BЈовић's user avatar
8 votes

Should I use other framework's namespaces in my code?

Namespaces have two main functions: Provide unique names for symbols; Group related symbols. For the unique names, putting your symbols in someone else's namespace is a big NO NO. As community of ...
Kasper van den Berg's user avatar
8 votes
Accepted

Why would you have a different namespace for each folder in a C# project?

The whole point of a namespace is that type names within the namespace are unique. So this is okay: namespace A { class Foo { } } namespace B { class Foo { } } This allows ...
John Wu's user avatar
  • 26.4k
7 votes

C# Namespace Ordering Coding Convention

When dealing with style, it is always more useful to take either an official style if one exists, or to use the one commonly adopted by the community of developers writing in a specific language. You'...
Arseni Mourzenko's user avatar
7 votes
Accepted

How can I cleanly handle deeply nested namespaces in C++?

this creates an entirely new issue where there are two separate hierarchies — one for namespaces, and another for the file system. That's not an issue at all though, it's perfectly normal. ...
Useless's user avatar
  • 12.6k
6 votes
Accepted

Why do we need namespaces when making XML serialization?

Simple answer: you don't. If you're serializing data as XML then you have to agree the details of the XML vocabulary with the consumers of the data. Perhaps you define it yourself, perhaps your ...
Michael Kay's user avatar
  • 3,474
6 votes

C++ namespace name isolation

What problem do you want to solve? That is completely unclear. As for your code, if you were a junior assigned to me, I would say: Your approach doesn't hide implementation details at all - they are ...
Sjoerd's user avatar
  • 2,926
6 votes

C# namespace and class naming convention for libraries

It's been a while since I've worked with C# or the .NET ecosystem so I can't say what the current recommended best practices are. I'd recommend a change to your names like this: Company Company.Text ...
FrustratedWithFormsDesigner's user avatar
6 votes
Accepted

C++ Is it okay to use nested classes as a way to namespace derived classes?

This is a very bad idea, because it breaks the Open/Closed Principle: Classes should be open for extension, but closed for modification. This means that it should be easy to "extend" your ...
Christophe's user avatar
  • 76.8k
5 votes

C# namespace and class naming convention for libraries

Using the same name for the namespace and the class inside it is problematic. If the namespace contains more than one class, why would other classes be put there? it doesn't feel right, because the ...
Arseni Mourzenko's user avatar
5 votes
Accepted

Is there an Ideal way of storing namespace-related elements?

Why not its own file within the namespace it belongs? For example, if I'm working on Legal Matters in my Domain project and I have an enum of MatterStatus, I'd place the enum with a MatterStatus.cs ...
jleach's user avatar
  • 2,682
5 votes
Accepted

Using a macro for a libraries namespace?

This technique is sometimes used to handle transitive dependencies on header only libraries. It is not generally a best practice. The problem: I am writing a C++ library. I put all of my declarations ...
amon's user avatar
  • 134k
5 votes
Accepted

C# Namespace Ordering Coding Convention

How would you determine the importance? The simplest way of ordering the usings is the to apply an alphabetical order; However, it is often useful the make the difference between usings pointing to ...
Olivier Jacot-Descombes's user avatar
5 votes

Refactor namespaces in a library while keeping backwards-compatibility

How do I keep my library backwards-compatible? The short answer is: you can't. If you move a type from one namespace to another, your choices are to manually create a delegation class in the old ...
David Arno's user avatar
  • 39.2k
4 votes
Accepted

Impacts of using class_alias() to maintain backwards compatibility in PHP

I have done it and it's possible, though there are a few pitfalls around autoloading to consider. I described the approach in a blog post: PHP: Using class_alias to maintain BC while moving/...
Fabian Schmengler's user avatar
4 votes

C++ namespace name isolation

If you really want constructive feedback on this approach, it would have been better to show some actual code that you think benefits from it. Then we'd have something concrete to discuss rather than ...
Useless's user avatar
  • 12.6k
4 votes

Using a domain name as C++ namespace

The easy solution would be one namespace per developer, and I keep track of which names are used. However, I would prefer something more built-to-last. In what way is your suggested solution not "...
Nicol Bolas's user avatar
  • 11.9k
4 votes

Same class and namespace name

.NET design guidelines requires I prefix for interfaces. It recommends singular form for classes (Collection suffix for everything implementing IEnumerable) and plural form for namespaces.
Dmitry Nogin's user avatar
4 votes

Why do we need namespaces when making XML serialization?

To build on Michael's answer, namespaces solve conflicts. So, if you have no conflicts you don't need them. If I had XML from two sources: Source 1: <Foobar> <Name>Foo</Name> &...
Jon Raynor's user avatar
  • 11.4k
4 votes
Accepted

What terms are used to differentiate the two xml forms, "<element></element>" and "<element/>"?

In Extensible Markup Language (XML) 1.1 (Second Edition) Section 3.1 Start-Tags, End-Tags, and Empty-Element Tags, it's called an "empty-element tag". If you were using XML and needed the formal term, ...
Thomas Owens's user avatar
  • 82.4k
4 votes

Load values from txt to variables in namespace

If you want to "avoid compiling", then it has to be data loaded at runtime. It can't be something from a global compile-time const variable. You can have an object with (perhaps static) functions that ...
Nicol Bolas's user avatar
  • 11.9k

Only top scored, non community-wiki answers of a minimum length are eligible