Re: [Pyobjc-dev] Objective-P?
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2009-11-12 11:54:15
|
On 12 Nov, 2009, at 11:59, Anders Hovmöller wrote: > > > On Thu, Nov 12, 2009 at 11:18 AM, Orestis Markou <or...@or...> wrote: > > On 12 Nov 2009, at 11:59, Ronald Oussoren wrote: > > > What really annoys me though is that I haven't been able to find a way to get clear integration of Cocoa and Python without changing the Python syntax, and without using manual translation of method names (as was used by the Java-Cocoa bridge). > > I've given some thought to that in the past, and of course I know it comes up on the list every couple of months. > > I think an important step is maintaing the order of the **kwargs dictionary: > > def set(self, **kwargs): > # construct method name from kwargs > # extract positional args from kwargs > objc.dispatch(methodname, args) > > > foo.set(Value=1, forKey='a') > foo.set(forKey='a', Value=1) > > If those calls could be differentiated in the body of 'set', would it not help? Some cases could be ambiguous, but in that case a warning could be emitted and the current convention could be used instead. > > Mapping python-style named parameters to objective-c message sending would probably incur quite a bit of overhead, and the end result, in my mind, ends up being not so readable either. I agree with your readability concerns, a generic interface for sending messages would look somethink like this: someObject(setValue=42, forKey="foo") It is far from obvious that this dispatches to a method, rather than calling a function with keyword arguments. This also doesn't work with methods that do not have arguments. Ronald |