[Pythonmac-SIG] pyobjc / cocoa

tmk lists@netelligent.biz
Wed, 16 Oct 2002 23:37:10 +0200


Yo,

FWIW, after reading all the proposals re: the method syntax. and 
writing some (a little) Python Cocoa code, I'm getting the strong 
feeling that I'd definitely go for bbum's suggestion to stay with the 
current "_" based naming convention.

> object.message_withFoo_(arg1, arg2)

It may not be the prettiest but after some testing, this syntax proved 
to be the easiest-to-understand and to map CORRECTLY with its ObjC 
counterparts (e.g. when I read.messageWithFoo(arg1, arg2) I found that 
I tend to expect only one argument (withFoo) while the underscore make 
it clear there are two of them and in what order).

Besides I remember how the ObjC syntax eventually made sense to me. It 
was after I read the following recipe:

"there are as many parameters to a message as they are colons in its 
name".

My litmus test for the syntax choice: "explain the mapping mechanism 
unambiguously in one sentence".

"replace the underscores in the python method name by colons and you'll 
get the name of the original ObjC method"

(Btw, is this the reason why there's hardly any doc with the PyObjC 
0.7.0 package ;-)

Wow. And again so many thanks and kudos to Ronald, Bill et al for this 
incredible tool.

Today I wrote my first real Cocoa app (other than those in the 
tutorials I've read) in python in a couple of hours.

This is all IMHO and just my .02 euros.

= tmk =


On Wednesday, Oct 16, 2002, at 10:54 Europe/Brussels, Jack Jansen wrote:

>
> 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 -
>
>
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
>