RubyCocoa and RubyObjC Q&A

Thursday, 23 Aug 2007

Alex Payne sent me some great questions about Ruby, RubyCocoa, and RubyObjC. Since they seemed to be of general interest, he’s agreed to let me post them here with my responses.

What was your impetus for writing RubyObjC after clearly investing a lot of time in the RubyCocoa community? Was there a particular technical direction you wanted to take that the RubyCocoa maintainers weren’t comfortable with, for example?

At C4, I presented my opinion that Objective-C is a great platform for building high-performing dynamically bindable components. That’s an important and generally overlooked feature, and it has made me a big fan of Objective-C. But Objective-C also has some significant inadequacies that could be fixed with another language layer—the same way that Objective-C improves on C and C improves on assembly language. Last year, I made a serious effort to use Ruby as that language.

For the first part of the year, that effort focused on RubyCocoa, which had been written five years earlier as a hobby project. I say “hobby” because it appeared that in its five year life, no one had successfully used RubyCocoa to write a serious application, not even its author. But if used carefully, it made for some interesting demos, and overall, Ruby seemed to be a better semantic match to Objective-C than its main alternative, Python. To prove it, I focused on creating documentation and significant examples, culminating in the console that I published last year in August. That helped debug RubyCocoa and also seemed to generate a lot of interest in using Ruby to write Cocoa apps.

I started RubyObjC in September 2006, right after Apple’s WWDC. There, Apple announced that they were making a big push into RubyCocoa with the goal of making Ruby a viable language for application development on Leopard. This included shipping supported versions of the RubyCocoa and PyObjC bridges with Leopard. Our first difference was over Ruby’s place in the tool chain. I wasn’t so interested in 100% Ruby apps; for my projects, I wanted a glue language that was simple, stable, and fast. Apple’s goal was broader and called for more change (churn) in the RubyCocoa code base. Bug fixes and performance improvements were less important, because to Apple, the release date that mattered was Leopard’s. So rather than bump into all the changes Apple was making, I decided to start working directly with the Objective-C runtime. That led to a completely new bridge, RubyObjC.

I think that RubyObjC makes the bridging process clearer; it includes Ruby interfaces to all the major elements of the ObjC runtime. Because I had no interest in writing 100% Ruby apps, I emphasized speed and stability first. In my experience with it, I was able to write things in RubyObjC that I could not get working in RubyCocoa. Since then, Laurent Sansonetti at Apple has fixed a lot of bugs in RubyCocoa and has even pulled in a few ideas from RubyObjC, but I haven’t used RubyCocoa since October 2006. That’s when RubyObjC became viable enough for me to switch all of my examples and projects over, and I haven’t needed to go back.

Are the two projects competitors, complimentary, or serving different purposes altogether? If they’re competitors, would you recommend RubyObjC over RubyCocoa to someone getting started with Ruby Cocoa development? Why or why not?

For me, they were competitors. I stopped using RubyCocoa once I had RubyObjC, and when I did, my work started moving a lot faster. I don’t have a lot of time to spend supporting RubyObjC, so if you want support (from Apple), it’s best to use RubyCocoa. But if you want an open toolkit for bridging Ruby and ObjC, RubyObjC is worth a look. It’s now on RubyForge and released under the Ruby license. Maybe it’s because I wrote it, but I think that RubyObjC is much easier to read and maintain. And since I started in September and had a working bridge in October, how complex could it be?

Have you had any communication with Apple regarding the place of Ruby in their development hierarchy? Do you know if RubyCocoa and/or RubyObjC will ship with Leopard?

My RubyCocoa web site gets a lot of hits from Apple, but I haven’t had much contact with people there. Last year I had a promising conversation with someone who abruptly disappeared on me; I hear that’s a common experience. But I now know Laurent Sansonetti fairly well (and even gave him an early preview of Nu). Laurent is in charge of getting RubyCocoa ready to be included in the Leopard release. He’s been doing a great job at this; my decisions have been in no way related to his work.

Do you think it’s feasible to develop a Cocoa application in pure Ruby that’s indistinguishable from its Objective-C counterparts? Could an application with a lot of Mac-like polish (ex: Transmit, MarsEdit, OmniFocus) be written in Ruby, or are there certain areas of Cocoa development that are off-limits to RubyCocoa/ObjC?

As I understand it, that’s Apple’s goal. So the answer is eventually, maybe, yes. It might be worth a try for an indie developer, but I wouldn’t bet anyone else’s money on it yet. Regardless, you owe it to yourself and your users to spend some time reading the source code for any bridge or glue language you use professionally. You don’t want to wait until something breaks.

With Ruby, Python, and other established scripting languages, even the best bridges come with some serious challenges that counter their advantages. You can make them work, but that doesn’t mean there isn’t a better way. For example, F-Script is much better integrated with Objective-C than Ruby or Python ever will be. And then there’s my other project, Nu.

Comments (4) post a reply
  1. Laurent Thursday, 23 Aug 2007, 06:38 PM PDT

    Thanks Tim for this post, I hope it will clarify the situation.

    I personally think that having 2 bridges in the wild doesn’t hurt. Competition is always good, and both bridges are in my opinion a bit different and can serve different purposes.

    RubyObjC, from what I could see, seems very straight and simple, in the way it does bridging. On the other side, RubyCocoa sounds more advanced, provides some automatic behaviors, and also seems to have more features.

    RubyCocoa should now be very stable, we didn’t receive any important crash since a long time. The unreliable parts have either been fixed or rewritten. Lots of unnecessary code (there for historical reasons) was removed. I also did some serious benchmarking of the core to eliminate unnecessary code paths (DTrace was very useful to do that). And there is also this other project, BridgeSupport, which RubyCocoa implements to access static APIs and also polish the bridged APIs. Quite lately, I also worked on supporting Ruby threading with RubyCocoa (which required patching the interpreter).

    There is theoretically no reason why people couldn’t write a complete Mac application using Python or Ruby. Here is a nice success story: http://developer.apple.com/business/macmarket/checkout.html . I recommend to download the demo version from their website and give it a try, you won’t even feel that it’s written in Python :-)

  2. grrrr Thursday, 23 Aug 2007, 11:22 PM PDT

    In the last paragraph you equal python and ruby in performance but ruby is still a lot slower than python. That it is feasible to use python for a application like checkout is not a guarantee that that will also work in ruby.

  3. Tim Thursday, 23 Aug 2007, 11:37 PM PDT

    If you had seen my demo at C4, you wouldn’t worry about speed. Ruby’s speed is not the problem. When performance is an issue, you can easily rewrite the slow parts in Objective-C. But an application like Checkout can be mostly written by hooking together objects that are already in Apple’s libraries (objects implemented with Objective-C).

  4. Laurent Friday, 24 Aug 2007, 04:48 AM PDT

    Exactly, as Tim said you can mix both Objective-C and Ruby in the same project, even in single classes (some methods can be “native” and others “interpreted”), and usually the hard work is done by Apple frameworks, which are implemented using compiled languages.

    I don’t think there is a checkout-equivalent app written in Ruby (as big and polished I mean), but I personally don’t think it would be impossible to write one. There are a few RubyCocoa apps around, even some commercial ones like PackRat: http://infinitenil.com/packrat/ . There is also the OSX version of LimeChat (the most popular IRC client in Japan) which is under development, but still very stable: http://limechat.sourceforge.net/ . I also know about a new company that uses RubyCocoa for a couple of user-oriented projects, that should be commercially released in the following months. So I would say, it’s probably a matter of time.