[Pyobjc-dev] Re: [Pythonmac-SIG] pyobjc / cocoa
Brought to you by:
ronaldoussoren
From: Jack J. <Jac...@cw...> - 2002-10-16 13:17:28
|
[I've added pyobjc-dev to the distribution] On Wednesday, October 16, 2002, at 02:28 , Ronald Oussoren wrote: >> Something that is open to discussion, I think, is how to map ObjC >> names to Python names. The current PyObjC code supports two >> compile-time options, object.message_withFoo_(arg1, arg2) and another >> that I forget with even more underscores in there (this mapping is >> ambiguous: it maps to both [object message: withFoo:] and to [object >> message_withFoo:]). The Java-ObjC brigde has simply defined sensible >> static mappings for all names used in Cocoa, and the above would >> probably become something like object.messagewithFoo() or >> object.messageWithFoo(). Python's current method is more flexible, but >> boy does it lead to ugly method names in your code... > > Changing the mapping from Objective-C names to/from Python names is > definitely open for discusion. > > BTW. The current PyObjC no longer supports object.message__withFoo__. I think that what I would like is one static scheme that is the same (or almost the same) as the Java/ObjC naming scheme, plus a fallback scheme (which could be the current message_withFoo_ scheme). There may be a problem here with overloading, though: if I look at AppKitJava there's often multiple ObjC selectors that map to one Java method name, I'm not sure how they handle this, especially in the face of overriding ObjC methods from Java. The static scheme could simply be a Python dictionary (or an NSDictionary, but a Python dictionary is easier to initialize, I guess) that we initialize with Python code, where the Python code is generated by running /Developer/Java/Jobs/*.jobs through a script. Fastest is probably to create both Python->ObjC and ObjC->Python dictionaries. Is it still possible to have two name mapping schemes, where first one is tried and then the other? Or would this wreak havoc now that we have two-way inheritance and such? Hmm, even if that isn't possible we could cop out: if the method name translation routine finds that a certain name isn't in the dictionaries it would simply add it. Or (more cumbersome, but safer) there could be a (Python) API MapObjCSelector('message:withFoo', 'messageWithFoo') which could then also check that this mapping doesn't conflict with another one. With such a scheme the Python programmer would have to declare any new ObjC messages it uses, but the question is how often this will happen. -- - Jack Jansen <Jac...@or...> http://www.cwi.nl/~jack - - If I can't dance I don't want to be part of your revolution -- Emma Goldman - |