Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [namespace]

Namespaces are a language feature of many programming languages, allowing local reuse of class and variable names.

Filter by
Sorted by
Tagged with
1 vote
3 answers
367 views

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

I can't see how having a namespace for each folder makes sense. As near as I can tell, the point of having namespaces is to avoid name conflicts. But, Microsoft, in their namespace naming conventions, ...
user avatar
0 votes
1 answer
105 views

aliases for namespaces in headers?

Everytime I write a header I end up doing something like this: #ifndef D723E2D5_1943_4166_87CC_73F5C9C47544 #define D723E2D5_1943_4166_87CC_73F5C9C47544 #include "RandomIntegers.hpp" ... #...
user avatar
  • 161
1 vote
1 answer
340 views

Namespace hierarchy in C#

I have a C# class library shared among several applications. The library is divided into a few smaller components which have dependencies shown in the picture below. Each component is placed in its ...
user avatar
  • 119
0 votes
0 answers
80 views

Is it a bad practice to have a class with a namespace that goes "out" of it's project name?

I have a solution with multiple projects, lets suppose there's one project with the name Company.Name.Foo.Bar. If I declare a class inside the project Company.Name.Foo.Bar but with a namespace Company....
user avatar
  • 329
1 vote
1 answer
188 views

Is it a good practice to have XML document with no-namespace elements in the middle

I have an XML looking like this: <?xml version="1.0" encoding="utf-8"?> <n0:OrderConfirmation xmlns:n0="http://company.org/interface/MVSI" xmlns:ord="...
user avatar
0 votes
3 answers
170 views

Using the symbol ⎋ to denote any "escape" in Javascript, CSS, HTML etc

I know that: Computer keyboards have an Escape Key The symbol for the Escape Key is U+238B Broken Circle with Northwest Arrow (⎋) and I also know that: HTML5 & CSS3 both have escape characters ...
user avatar
3 votes
3 answers
595 views

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

I understand the rationale of avoiding using namespace std - this defines too many casual names the developer may not be even aware of. I tried to work around the problem with the help of using ...
user avatar
  • 689
3 votes
2 answers
261 views

Am I using namespaces wrong?

I'm obsessed with organization - it's probably the real reason why I enjoy coding. So I namespace everything. But I'm just curious if I'm doing it wrong by being redundant. Consider this, which I ...
user avatar
3 votes
2 answers
322 views

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

I'm writing some tools to be used on the top a specific framework, in C#. Most of my code should use the naming convention CompanyName.TechnologyName[.Feature][.Design], but I wonder if in some cases ...
user avatar
  • 193
4 votes
2 answers
501 views

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

The first language that I truly learned was Java. In it, it is very syntactically easy to nest classes in an essentially arbitrarily complex package hierarchy, which keeps the code organized. It is ...
user avatar
  • 869
1 vote
0 answers
101 views

Can/should multiple application contexts share a common microservice in a single namespace?

My current employer has a single namespace into which all microservices for all projects are deployed. Projects A, B and C all use microservice x in this common namespace: Rather than each design ...
user avatar
1 vote
2 answers
702 views

Refactor namespaces in a library while keeping backwards-compatibility

We developed a generic .NET library for our line-of business applications. This is what our namespace/class structure looked like 5 years ago: ... AcmeCorp.Tools.ExcelWriter AcmeCorp.Tools....
user avatar
  • 9,220
0 votes
2 answers
90 views

When no other class ever needs to touch the (nested) class - should I always make it a (private) nested class?

And what is the recommended file structure? The question is a bit similar to this one, but I'm looking for more explicit recommendations. In theory I think it's a good concept to keep files short ...
user avatar
  • 305
4 votes
1 answer
1k views

Suggestions for documenting namespaces with Doxygen

Consider several C++ classes which are all defined in a particular namespace. For cleanliness, each class is located within its own file, and are each well-documented. For the purposes of completing ...
user avatar
-2 votes
1 answer
49 views

Grouping types in a single project [duplicate]

I have many models in my project that are unrelated to each other. I wanted to group them but I wonder what's better: Folder/namespace per group Group1.Constants, Group2.Constants Group1.Models, ...
user avatar
  • 1,401
-2 votes
1 answer
962 views

Shared classes between namespaces, how to distribute them?

Some time ago I read from this book that namespaces inside libraries should be distributed in a way that inner namespaces have more concrete classes than their parent namespaces. We can find an ...
user avatar
  • 99
5 votes
2 answers
6k views

C# Namespace Ordering Coding Convention

Is there a general coding convention in ordering namespaces? Is it always order of importance, or alphabetical? Currently I order by main important ones first. I know it does not affect program, just ...
user avatar
0 votes
1 answer
119 views

C# Separate Online Store into Different Solutions and Nugets

I am creating an Online Shopping Cart store. It is built through Net MVC Core. There is a Front End View website: html, css, razor. Then we have backend code design for Customers: including shopping ...
user avatar
2 votes
1 answer
150 views

Should namespaces within a single project act as boundaries?

When working within a single project that contains multiple namespaces, should these namespaces be treated as boundaries? Or is it acceptable that any namespace can access any other namespace? For ...
user avatar
4 votes
2 answers
888 views

How can I avoid using global variables in simple Javascript SPA?

To learn Javascript I am building a simple Single-Page Application. It is a basic slideshow app that needs only to process some basic settings and execute some behaviors. The basic structure of my ...
user avatar
  • 41
1 vote
1 answer
4k views

Using a macro for a libraries namespace?

In some code bases (such as hydra, and thrust's tuple implementation) I see namespaces defined entirely with macros. It appears the reason for this is so that you can configure the namespace to your ...
user avatar
  • 948
0 votes
3 answers
693 views

When it isn't right to add types to a well known namespace?

For the purpose of writing a library, I found to be nice to add types to some well known namespace. Example: I've written a couple of extension methods for BinaryWriter and naturally put them in ...
user avatar
  • 727
6 votes
2 answers
2k views

C# Names of Namespaces with version suffix

In official Microsoft docs: ✓ DO use a stable, version-independent product name at the second level of a namespace name. But in Reference Source, the following namespaces ends with Version: ...
user avatar
4 votes
2 answers
394 views

Is there a valid use case for the using namespace directive?

I looked trough some of my older code and found that I was using the using namespace directive. From what I read in a lot of google results, it seems that it is never a good idea to use this. Is there ...
user avatar
  • 197
8 votes
2 answers
5k views

Avoiding conflicting namespace and class name

Say I am developing a Calculator application. It has one class called: Calculator. Therefore my namespace structure would look like this: MyCompany.Calculator.Core.Calculator Unfortunately, this ...
user avatar
  • 6,827
2 votes
3 answers
710 views

Is it considered a bad practice to import symbols in bulk to a global namespace irrespective of the programming language?

In the C++ community it is considered an extremely bad practice to type: using namespace something; in the scope of the file for any reason, even if the project size is only a few hundred lines at ...
user avatar
  • 3,317
4 votes
2 answers
646 views

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

In the title, with namespace-related elements, I refer to Enums, Delegates and other elements that do not belong to a single class, but to the whole namespace, or application. I know that I can cram ...
user avatar
-1 votes
6 answers
4k views

C++ namespace name isolation

It's been considered for a reason, that using for namespaces/names is side-effect-prone, and generally, fully qualified names should be preferred. I've come up with an approach on that, which I ...
user avatar
31 votes
4 answers
35k views

C# namespace and class naming convention for libraries

I'm building libraries with various small utility functions in C#, and trying to decide on a namespace and class naming convention. My current organization is like this: Company Company.TextUtils ...
user avatar
  • 515
5 votes
1 answer
1k views

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

Scenario: An open-source PHP project that has existed for several years has too many classes in the main namespace that we want to refactor some of them into another namespace, but we have a widely ...
user avatar
  • 618
3 votes
0 answers
313 views

How to structure the project folders of my application's service layer?

I want to know how to structure my Service Layer I have thought about something like that: Assembly called SomeNamespace.Service. Have a seperate folder for each problem domain (SomeNamespace....
user avatar
5 votes
2 answers
8k views

Is including headers inside a namespace always a bad idea?

The replies in this post come very strongly against including headers inside a namespace and Doxygen is confused if that is done (which suggests that its team did not consider that usage either). I ...
user avatar
0 votes
1 answer
121 views

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

I'm writing a boolean that will toggle between these two forms for writing markup into my strings, but I do not know what I should name my boolean. bool setMarkupForm(bool markupForm); Is not ...
user avatar
  • 3,319
0 votes
3 answers
371 views

Load values from txt to variables in namespace

I am currently working in an aleady developed C++ project. The existing files are the following: -main.cpp -HydroModel.cpp -ODESys.cpp -HydroModel.hpp -ODESys.hpp -ODESysSol.hpp In the file ...
user avatar
3 votes
3 answers
2k views

namespaces and header guards with naming conflicts

C++ has namespaces to prevent collisions of things with the same name. Header guards serve a different purpose. They prevent includeing the same header twice. However, they can suffer from the same ...
user avatar
  • 3,496
2 votes
1 answer
95 views

In what namespace would I place "Doers"

This might sound weird and probably is, but I am struggling to find a good place where to place what I will just call "Doers" for lack of a better name. Basically, my project currently has these ...
user avatar
  • 589
1 vote
3 answers
3k views

Should class names reflect namespace name?

Is it generally considered good practise for a class name to reflect the namespace name it exists under, or should the namespace name implicitly be considered part of the class name? For example, ...
user avatar
  • 239
4 votes
1 answer
137 views

Regarding the Organization of Bit Shifting Utility Functions in C++

I am developing a project in C++ that deals with converting an ASCII hexadecimal string representation into binary. The class also has utilities in it for extracting info from the string. Right now ...
user avatar
2 votes
2 answers
1k views

Using a domain name as C++ namespace

What would be a good system to use domain names as C++ namespaces in order to avoid name clashes between developers? The idea appears to be popular in the Java world. We cannot use namespace example....
user avatar
5 votes
3 answers
14k views

Same class and namespace name

I have a problem how to go about naming my namespaces and classes. I already figured they shouldn't both have the same name, as it causes all kinds of problems. Most notable problem for me is that I ...
user avatar
  • 153
3 votes
2 answers
211 views

Why do we need namespaces when making XML serialization?

I know this might be a very basic question, but I'm new to XML serialization and spent hours trying to read different pages. PS: this is a programming language independent question.
user avatar
  • 147
8 votes
1 answer
20k views

Importing namespaces inside another namespace

I generally like to organize classes I make into modules by using namespaces, and I also don't go more than 2 namespaces deep but it's still painstakingly hard to fully qualify everything. I've ...
user avatar
3 votes
1 answer
418 views

"Vendor" name changes when the vendor name changes

PHP (PSR-2, anyway) recommends using the vendor name as the root namespace for projects. At face value, this seems to mean we should use the current name of our company. But I work for an enterprise ...
user avatar
  • 2,095
7 votes
3 answers
7k views

C++ Extensible namespaces - how to force declarations back into global namespace

It is good programming style to include all necessary dependencies in a header that references them. Often this includes declarations that are placed in the STD & global namespaces (like cstdio). ...
user avatar
  • 91
3 votes
0 answers
538 views

Why aren't there traditional namespaces in TypeScript? How do I group classes without them?

"Traditional" namespaces in the sense that Java, C#, and PHP use it. Spaces to organize related classes and sub-namespaces that span across multiple files. How do I rewire my brain to think without ...
user avatar
12 votes
1 answer
8k views

static globals and anonymous namespaces in C++

Why did C++ make any distinction between static globals (internal linkage) and symbols in an unnamed namespace (external linkage, but no way to refer to it from outside anyway), when introducing the ...
user avatar
  • 8,143
3 votes
1 answer
102 views

Namespace by topic or by purpose? [closed]

The project I'm working on has quite a few classes. These classes can be grouped in two different ways. I'm trying to decide which grouping is best as for namespacing. Currently I a set of user facing ...
user avatar
  • 1,031
21 votes
4 answers
6k views

Semantically more appropriate package name than `util` for the following things?

As a strawman consider the package java.util it is a dumping ground for various classes that in most cases do not share anything in common other than the person that put them there was lazy or ...
user avatar
6 votes
2 answers
3k views

Nested classes via a getter (to emulate namespacing)

So, we all know that ES6's introduced syntax is definitely sugar over what we've been doing, previously. That being said, we still don't have namespaces (which would be nice...) The problem that I'm ...
user avatar
  • 558
1 vote
1 answer
182 views

Clojure NameSpace Design

I am new to Clojure and trying to get a handle on organizing a project's namespaces. I am working on a solver for the knapsack problem. Currently, I have broken the modules into files, but everything ...
user avatar