Cocoa Language Options - Ruby and Python

Ruby is increasingly used for Cocoa development. Ruby has a Smalltalk-like object model with Perl-like syntax. The object model means that it is a good fit for Cocoa, although the syntax is an acquired taste. There are two versions of Ruby available for OS X. RubyCocoa uses the standard Ruby implementation and provides a bridge to Objective-C, allowing the use of Objective-C objects. MacRuby is a new implementation that compiles Ruby objects to use the same underlying object model as Objective-C. Python can also be used, via the PyObjC bridge. This is similar to RubyCocoa, in that it uses the existing Python implementation and simply provides access to Cocoa objects via a bridge. The biggest issue when implementing this kind of bridge is that Objective-C, like Smalltalk, uses infix parameters. The most common convention is to replace the colons in Objective-C method names with underscores. This is used in the Python and JavaScript bridges. Implementing a new bridge from a dynamic language is relatively easy. You can create a simple bridge using the NSProxy class to represent objects in your language on the Cocoa side and use the C foreign function call capability of your language to call the Objective-C runtime functions or send messages like perform Selector: from NSObject. Damien Pollet and I implemented a simple bridge from GNU Smalltalk in an afternoon using this mechanism.

Source of Information : Addison Wesley - Cocoa Programming Developers Handbook (December 2009)


Subscribe to Developer Techno ?
Enter your email address:

Delivered by FeedBurner