Namespaces are a language feature of many programming languages, allowing local reuse of class and variable names.
Questions tagged [namespace]
98 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,950
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,852
45
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,006
33
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
- 555
29
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,279
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
22
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,178
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
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
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
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,068
- 2
- 23
- 34
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
- 9,209
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…
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
10
votes
1 answer
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 read that this was explicitly not a good use of…
Andy
- 2,045