[Pythonmac-SIG] pyobjc / cocoa

Jack Jansen Jack.Jansen@cwi.nl
Wed, 16 Oct 2002 10:54:46 +0200


On Wednesday, October 16, 2002, at 09:45 , Just van Rossum wrote:

> Seth Delackner wrote:
>
>> To expand on my previous comment in a different direction, why not:
>>
>> rt = pyobjc.runtime
>>
>> rt.call(obj, "message", "arg1name", arg1value, "arg2name", arg2value);
>> Which would directly map to:
>> [obj message arg1name:arg1value arg2name:arg2value];
>> although I'll be the first to admit I have no idea how to actually
>> affect that transform.
>
> I still know very little about ObjC, let alone pyobjc, but in my ideal 
> would be
> something like:
>
>   obj.message(arg1name=arg1value, arg2name=arg2value)

There's a fundamental problem with this: the "argnames" are really part 
of the Objective C method name. I.e. if you see  a call [object message: 
arg1 withFoo: arg2] you should think of "message:withFoo:" as the method 
name, *not* of "message:" as the message name and "withFoo:" as the name 
of an optional argument.

Within the ObjC environment the three methods [object message], [object 
message: arg1] and [object message: arg1 withFoo: arg2] have absolutely 
no relationship to each other. Trying to unify these is going to lead to 
some very ugly code at some point. For instance, how would you override 
"message:withFoo:" in a Python object subclassed from an ObjC object 
without overriding "message:"?

ObjC picked the "interspersed method names" (there's probably an 
official term for this) up from Smalltalk. And, incidentally, ABC, 
Python's predecessor, had this same syntax but it's one of the many 
things from ABC that Guido dropped for Python.

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...
--
- Jack Jansen        <Jack.Jansen@oratrix.com>        
http://www.cwi.nl/~jack -
- If I can't dance I don't want to be part of your revolution -- Emma 
Goldman -