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
2 votes
3 answers
591 views

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

I have many abstract classes that describe many abstract ideas and objects. These classes have many complex relationships with each other, and I realize that while writing code with some of the ...
nreh's user avatar
  • 151
3 votes
3 answers
2k 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, ...
Josiah_Maddux's user avatar
0 votes
1 answer
2k 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" ... #...
a a's user avatar
  • 261
1 vote
1 answer
1k 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 ...
Honza Vojtěch's user avatar
0 votes
0 answers
402 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....
Vencovsky's user avatar
  • 351
1 vote
1 answer
331 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="...
рüффп's user avatar
0 votes
3 answers
381 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 ...
Rounin's user avatar
  • 275
3 votes
3 answers
1k 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 ...
h22's user avatar
  • 917
3 votes
2 answers
301 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 ...
errno_44's user avatar
3 votes
2 answers
448 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 ...
Roberto's user avatar
  • 193
4 votes
2 answers
968 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 ...
john01dav's user avatar
  • 879
1 vote
0 answers
170 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 ...
8bitjunkie's user avatar
3 votes
2 answers
1k 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....
Heinzi's user avatar
  • 9,696
0 votes
2 answers
190 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 ...
Dirk Boer's user avatar
  • 377
4 votes
1 answer
2k 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 ...
John Go-Soco's user avatar
-2 votes
1 answer
60 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, ...
Konrad's user avatar
  • 1,559
-1 votes
1 answer
1k 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 ...
amedina's user avatar
  • 109
6 votes
2 answers
7k 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 ...
CarSpeed87's user avatar
0 votes
1 answer
122 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 ...
MarkAllison's user avatar
2 votes
1 answer
266 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 ...
Jason Tyler's user avatar
4 votes
2 answers
1k 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 ...
sddaa's user avatar
  • 41
1 vote
1 answer
5k 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 ...
Krupip's user avatar
  • 1,270
0 votes
3 answers
719 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 ...
aybe's 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: ...
Jawad Al Shaikh's user avatar
4 votes
2 answers
522 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 ...
Hakaishin's user avatar
  • 197
8 votes
2 answers
7k 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 ...
w0051977's user avatar
  • 7,061
2 votes
3 answers
868 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 ...
gaazkam's user avatar
  • 3,883
4 votes
2 answers
907 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 ...
oneManArmin's user avatar
-1 votes
6 answers
5k 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
40k 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's user avatar
  • 535
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 ...
SOFe's user avatar
  • 668
3 votes
0 answers
460 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....
Christian Gollhardt's user avatar
6 votes
2 answers
11k 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 ...
AlwaysLearning's 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 ...
Anon's user avatar
  • 3,593
0 votes
3 answers
432 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 ...
Muthahu6's 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 ...
null's user avatar
  • 3,546
2 votes
1 answer
97 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 ...
F.P's user avatar
  • 599
1 vote
3 answers
4k 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, ...
Daniel's user avatar
  • 239
4 votes
1 answer
142 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 ...
Petyr Panos's user avatar
2 votes
2 answers
2k 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....
Lasse Kliemann's user avatar
5 votes
3 answers
17k 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 ...
Łukasz's user avatar
  • 153
3 votes
2 answers
229 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.
AhmedWas's user avatar
  • 147
8 votes
1 answer
23k 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 ...
John Mark Caguicla's user avatar
3 votes
1 answer
426 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 ...
kojiro's user avatar
  • 2,105
8 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). ...
bgulko's user avatar
  • 101
3 votes
0 answers
549 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 ...
budhajeewa's user avatar
13 votes
1 answer
9k 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 ...
Deduplicator's user avatar
  • 8,701
3 votes
1 answer
108 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 ...
innova's user avatar
  • 1,041
22 votes
4 answers
8k 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 ...
ndugger's user avatar
  • 568