[cfe-dev] Adding namespaces to Objective-C

Jean-Daniel Dupas devlists at shadowlab.org
Fri Nov 12 00:16:03 PST 2010


Le 12 nov. 2010 à 02:12, Jens Ayton a écrit :

> On Nov 9, 2010, at 22:54, Owen Shepherd wrote:
>> 
>> 
>> The hardest aspect seems to be namespacing of selectors; it seems to be an issue which I haven't really seen affecting other languages, and seems a rather difficult one to solve elegantly, though I must ask: Is it a major issue in practice? I haven't found it to be, and haven't found other people claiming it to be either, though I don't claim that it doesn't exist.
> 
> Yes. Selector conflicts are more subtle and therefore nastier than class name conflicts, and far more onerous to handle using prefixes. Given the choice, I’d much rather have namespaces for selectors than for classes.

Class conflict is a real problem when you develop plugins. If two plugins developers use the same third party toolkit for example, the host application ends up trying to load each class from this toolkit 2 times, and you don't have any guarantee that they are from the same version of the toolkit.

Unfortunately, I'm not sure this problem can be solved by namespaces, as this is more a problem of class visibility. Unlike in C/C++ where you can declare classes as hidden symbols linked at compile time, in Obj-C all classes are always exported, and loaded in a global pool by the runtime.

> (An advantage of only namespacing selectors is that you could use the most elegant namespace separator I’ve come across: a space. [object namespace method] is unambiguous, as long as you don’t also allow [namespace Class method]. I don’t expect this idea to win the day, though.)
> 
> As a practical example of a selector conflict, I once had an app crash on one user’s machine because it had a convenience method -[NSDictionary setDouble:forKey:], and an input manager hack defined a -setDouble:forKey: with conflicting semantics. I’ve heard of people being bitten by conflicts with methods introduced in superclasses in system updates, too.
> 

Input Managers are a plague and I'm happy that Apple finally blocked them.

> -- 
> Jens Ayton

-- Jean-Daniel








More information about the cfe-dev mailing list