<p>I think most C++ programmers here would agree that polluting the global namespace is a bad idea, but are there times when this rule can be ignored?</p>

<p>For example, I have a type that I need to use all over a particular application - should I define it thus:</p>

<pre><code>mytypes.h

typedef int MY_TYPE;

foo.cpp

MY_TYPE myType;
</code></pre>

<p>Or use a namespace:</p>

<pre><code>mytypes.h

namespace ns {
typedef int MY_TYPE;
}

foo.cpp

ns::MY_TYPE myType;
...
using namespace ns;
MY_TYPE myType;
</code></pre>

<p>Which do you prefer?  Are there times when it is acceptable to use the first method?</p>

I use namespaces for partitioning library code from application-specific code, and in a big project to partition the various modules that make up the project.
The global namespace is thus useful for application-specific types and functions that are used across multiple modules in the application.
So, if your
```
MY_TYPE
```
is used throughout your application, put it in the global namespace, otherwise put it in a named namespace.