Questions tagged [namespace]
Namespaces are a language feature of many programming languages, allowing local reuse of class and variable names.
97
questions
2
votes
3
answers
1k
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 ...
28
votes
4
answers
35k
views
Why do we need URIs for XML namespaces?
I am trying to figure out why we need URIs for XML namespaces and I cannot find a purpose for that. Can anyone brighten me a little showing their use on a concrete example?
EDIT:
Ok so for instance:...
10
votes
1
answer
3k
views
Separate namespace just for exceptions?
I was doing a code review and came across something odd which I've never seen before. The developer decided to create a sub-namespace just to contain all the assembly's exceptions.
I thought I had ...
1
vote
1
answer
395
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="...
46
votes
6
answers
9k
views
Why is "tight coupling between functions and data" bad?
I found this quote in "The Joy of Clojure" on p. 32, but someone said the same thing to me over dinner last week and I've heard it other places as well:
[A] downside to object-oriented programming ...
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, ...
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"
...
#...
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 ...
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 ...
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 ...
0
votes
0
answers
425
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....
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 ...
0
votes
3
answers
455
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
...
2
votes
1
answer
4k
views
Dynamic Class Inheritance For PHP
I have a situation where I think I might need dynamic class inheritance in PHP 5.3, but the idea doesn't sit well and I'm looking for a different design pattern to solve my problem if it's possible.
...
3
votes
2
answers
308
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 ...
3
votes
2
answers
494
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 ...
1
vote
2
answers
7k
views
How to use namespaces to separate interface from implementation, in c++?
As far as I can tell, you can make your interface known to others by providing your .h file. Your .cpp is the implementation. Then they can see the function names, the parameter types, the return ...
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 ...
4
votes
2
answers
1k
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 ...
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 ...
1
vote
0
answers
177
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 ...
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....
0
votes
2
answers
220
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 ...
21
votes
4
answers
12k
views
Use `using` in C++ or avoid it?
Discounting subtly different semantics due to ADL, how should I generally use using, and why? Is it situation-dependent (e.g. header which will be #included vs. source file which won't)?
Also, should ...
-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 ...
-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, ...
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 ...
-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 ...
6
votes
2
answers
8k
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 ...
2
votes
1
answer
297
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 ...
1
vote
1
answer
6k
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 ...
0
votes
3
answers
721
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 ...
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:
...
4
votes
2
answers
547
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 ...
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 ...
2
votes
3
answers
887
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 ...
4
votes
2
answers
969
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 ...
21
votes
1
answer
22k
views
Pros and cons of namespaces vs include/require in PHP?
I recently started using namespaces in PHP. When I first saw them, I thought that their syntax was ugly and I'd never use them. However, I created an autoloader (spl_autoload_register) that makes it ...
31
votes
4
answers
41k
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
...
5
votes
1
answer
2k
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 ...
3
votes
0
answers
472
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....
2
votes
4
answers
4k
views
What are the good practices for including namespaces in C++ that avoid more typing?
I am starting out with C++ and almost everywhere I see there is these 2 sentences at the top.
#include <iostream>
using namespace std;
As I understand namespaces are something to keep names ...
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 ...
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). ...
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 ...
0
votes
3
answers
461
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 ...
3
votes
3
answers
3k
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 ...
2
votes
1
answer
98
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 ...
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, ...
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....