Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Until some other cool library you really want to use happens to also have a NSArray.

With proper namespaces/modules, such conflicts can be usually sorted out by renaming on import. With C and Objective-C, good luck.



If a cool library you want also has a class named NSArray, then you just refactor it by renaming on import like you just mentioned.

It's literally the exact same thing as what you're saying. Say I have one library in my project already - we'll call it BGAddressBook. And then I find another library that I really want to add that also happens to be named the exact same - BGAddressBook. So, I would refactor one of them (probably the one already in there to be BG1AddressBook or whatever). This is no different than having a library named BGAddressBook in ruby and wanting to use another library with the same namespace. You're going to have to change one or the other's namespace to work with both.

Properties don't matter and can collide with no problem. I can have a BGAddressBook with a name property and a BGSomethingElse with a name property. Doesn't matter. It'd be the same as BGAddressBook::Name and BGSomethingElse::Name.


How do you refactor third party libraries delivered as binary?


How would you refactor a third party library delivered as a binary in a language with namespaces?


By importing names from that namespace and aliasing them. Or by creating another namespace and importing them there.

You can't seriously argue that "NSArray" as a single string is the same thing as (hypothetical) "NS.Array", where both "NS" and "Array" and the thing at "NS.Array" are semantically different things. Don't get me wrong, I love Smalltalk and Erlang - both languages suffering from the same problem - but I can recognize a shortcoming when it bites my arm off.


I was genuinely asking in my question above. I'm all for it as long as it makes sense. I've never messed with aliasing or anything like that - I'm decently fluent in Objective-C but have only really dabbled in ruby/js.

After looking around halfway through writing this, this looks pretty nice:

http://stackoverflow.com/questions/11091740/is-it-possible-t...

I see what you're saying. Maybe it's Stockholm Syndrome, but I do like knowing associated files in 3rd party libraries easily too. I don't know, I'll experiment with this more in ruby and see how it feels.


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...


    #include <coollib.h>

    namespace betterns = std;


The 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.


I just gave a C++ example, because you asked for one.

There are lots of module systems to choose from, and Objective-C offers none.


I 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: