3 ms·
Then there must be some other cool library you really want to use happens to also have the namespace "std" and a "vector" class inside...
by luikore 13y ago
Then there must be some other cool library you really want to use happens to also have the namespace "std" and a "vector" class inside...
- pjmlp 13y ago#include <coollib.h> namespace betterns = std;
- swift 13y agoThe whole problem is that namespaces are open, and you can add to them from anywhere. This means a namespace alias is useless in this situation. There's no distinction between things put in namespace std by library A and things put there by library B - they are all equally valid members of namespace std. All that has been accomplished by the namespace alias is that before, both libraries were accessible through "std", and now, both libraries are accessible through both "std" and "betterns". Namespaces gives you the tools to make name clashes less likely, but they don't make them impossible. Generally to avoid clashes totally you need a central arbiter of name ownership like, say, the DNS registry, which is why naming your packages using inverted domain names was advocated by some people in the Java community.
- pjmlp 13y agoI just gave a C++ example, because you asked for one. There are lots of module systems to choose from, and Objective-C offers none.
- swift 13y agoI never asked for anything; perhaps you are confusing me with luikore. Namespaces and modules do not prevent name clashes, at least in any language that I'm aware of. Even with a more sophisticated system like Haskell's, you're still out of luck if you have a package name clash. (And getting to the point where that's the limiting factor requires GHC extensions.) What namespaces/modules buy you with respect to name clashes is just that they make it possible to stomach longer names that make those clashes less likely. Are you aware of a programming language that does truly prevent name clashes through a namespace or module system? I'd be interested to hear of it.