[Rubycocoa-devel 528] Re: propose alternatives of the symbol-value-repeated-syntax

Back to archive index

Laurent Sansonetti lsans****@apple*****
Tue Dec 26 00:33:28 JST 2006


Hi Hisa-san,

On Dec 25, 2006, at 6:30 AM, Fujimoto Hisa wrote:

> Hi all,
>
> the apple-unstable have two formal way for messaging (objc method
> invocation) like the following:
>
>      nc = OSX::NSNotificationCenter.defaultCenter
>
> (a) [primitive]
>
>      nc.addObserver_selector_name_object_(self,
>                                           'historyDidLoad:',
>
> OSX::WebHistoryLoadedNotification,
>                                           myHistory)
>
> (b) syntax sugar for the (a)
>
>      nc.addObserver_selector_name_object(self,
>                                          'historyDidLoad:',
>
> OSX::WebHistoryLoadedNotification,
>                                          myHistory)
>
> Sometimes the underscored-selector-syntax looks too long, and I think
> it's a bit ugly. And that it often make source code illegible.  So I
> want to keep on using the symbol-value-repeated-syntax.
>
> Well, I propose alternatives of the symbol-value-repeated-syntax for
> messaging (objc method invocation) like the following example. it's
> better to implement this as a independent method from method_missing,
> and it should be nothing to effect to method_missing.
>
> (c) objc_send (the name is tentative)
>
>      nc.objc_send  :addObserver, self,
>                    :selector,    'historyDidLoad:',
>                    :name,        OSX::WebHistoryLoadedNotification,
>                    :object,      myHistory
>
>      nc.objc_send( :addObserver, self,
>                    :selector,    'historyDidLoad:',
>                    :name,        OSX::WebHistoryLoadedNotification,
>                    :object,      myHistory )

I totally agree on this, an independent method is a good idea.

> (d) alias for (c) as syntax sugar
>
>      nc._  :addObserver, self,
>            :selector,    'historyDidRemoveAllItems:',
>            :name,        OSX::WebHistoryAllItemsRemovedNotification,
>            :object,      myHistory
>
>      nc._( :addObserver, self,
>            :selector,    'historyDidAddItems:',
>            :name,        OSX::WebHistoryItemsAddedNotification,
>            :object,      myHistory )

I would not recommend this, as some libraries already define #_ (for  
example, Ruby/Gettext), and the name is confusing to me. Perhaps  
another name?

Also, we can talk about your objc_export proposal!

http://www.fobj.com/hisa/d/20061222.html#p02

module OSX
   module NSBehaviorAttachment
     def objc_export(name, typefmt)
       name = name.to_s
       name = name[0].chr << name[1..-1].gsub(/_/, ':')
       if /[^:]$/ =~ name && /^.\d*@\d*:\d*[^\d]/ =~ typefmt then
         name << ":" end
       self.addRubyMethod_withType(name, typefmt)
     end
   end
end

As we discussed earlier on chat, I believe that it would be even  
better if we can hide the 'typefmt' definition to the user. Not all  
developers know the ObjC runtime encodings.

Instead of doing

   objc_export :WiiRemoteDiscoveryError, "v@:i"

You could do

   objc_export :WiiRemoteDiscoveryError, %w{void int}

Any though about this also? We could add both objc_send and  
objc_export at the same time :-)

Laurent



More information about the Rubycocoa-devel mailing list
Back to archive index