Namespaces are a language feature of many programming languages, allowing local reuse of class and variable names.
Questions tagged [namespace]
97 questions
46
votes
6 answers
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 is the tight
coupling between function and…

GlenPeterson
- 14,890
- 6
- 47
- 75
46
votes
4 answers
Why do so many namespaces start with com
I've noticed that a lot of companies use "reverse domain name" namespaces and I'm curious where that practice originated and why it continues. Does it merely continue because of rote practice, or is there an outstanding architecture concept I might…

jcolebrand
- 1,016
- 1
- 10
- 19
45
votes
5 answers
Best practices for using namespaces in C++
I have read Uncle Bob's Clean Code a few months ago, and it has had a profound impact on the way I write code. Even if it seemed like he was repeating things that every programmer should know, putting them all together and putting them into…

Dima
- 11,822
- 3
- 46
- 49
31
votes
4 answers
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
public class TextUtils {...}
Company.MathsUtils
…

user
- 525
- 1
- 5
- 10
28
votes
4 answers
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: I have this from…

Patryk
- 1,269
- 3
- 13
- 14
22
votes
4 answers
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 uninspired to come up with a more semantically correct…
user7519
21
votes
1 answer
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 so that I never have to write an include/require…

NobleUplift
- 815
- 3
- 7
- 16
21
votes
5 answers
Using static classes as namespaces
I have seen other developers using static classes as namespaces
public static class CategoryA
{
public class Item1
{
public void DoSomething() { }
}
public class Item2
{
public void DoSomething() { }
…

user394128
- 463
- 1
- 3
- 7
20
votes
4 answers
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 I prefer ::std:: or std::?
Namespace-level using…

user541686
- 8,074
- 8
- 38
- 49
14
votes
4 answers
Number of Classes in a Namespace - Code Smell?
I have a C# library that's used by several executables. There's only a couple namespaces in the library, and I just noticed that one of the namespaces has quite a few classes in it. I've always avoided having too many classes in a single namespace…

Tim Claason
- 913
- 7
- 11
14
votes
2 answers
Why use typedefs for structs?
in C (ANSI, C99, etc.), structs live in their own namespace. A struct for a linked list might look something like this:
struct my_buffer_type {
struct my_buffer_type * next;
struct my_buffer_type * prev;
void * data;
};
It seems quite…

wirrbel
- 3,018
- 2
- 21
- 33
13
votes
1 answer
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 latter?
Are any of those reasons still valid, or…

Deduplicator
- 8,591
- 5
- 31
- 50
12
votes
1 answer
Naming convention for iOS/OSX open-source projects
Not always but most of the time, you will find iOS or Mac OS X open-source projects with names starting with the initial letters of the author first and last names. If a project were to be authored by Nick Leblanc, the project would be read as…

Stéphane Bruckert
- 344
- 1
- 12
11
votes
1 answer
Evaluating PHP namespaces
I'm at the pre-release stage of an open-source PHP project, one which I hope will be used by other developers in their own projects. The project doesn't currently support namespaces and I'm trying to evaluate if it should use namespaces or the PEAR…

VirtuosiMedia
- 4,089
- 4
- 33
- 43
11
votes
2 answers
How do I partially add PHP namespacing to a library without breaking existing code?
My company has created a modular PHP framework over the years, beginning long before PHP 5.3 added namespaces. Recently, we decided to start using namespaces in our library's new code, and we intend to namespace old code eventually. However, we have…

jimp
- 291
- 2
- 7