The first talk of the conference is by Rich Kilmer on MacRuby & HotCocoa.
He’s starting out by talking about the history of Apply and Ruby. The first time a version of Ruby was shipped with OS X was in 2002: Ruby 1.6.7 was shipped with OS X version 10.2. The next big development was in 2007, when Ruby 1.8.6, RubyGems, RubyCocoa and Rails were shipped with OS X version 10.5. Later this year, SnowLeopard will include Ruby 1.8.7, RubyGems, RubyCocoa and Rails 2.2.
Rich is telling us that one of Apple’s goals is to make OS X the best platform for Ruby developers. Another is to make Ruby a first-class Cocoa programming language on OS X. He hopes that it will become the best Cocoa programming language – a pretty tall order.
Now we’re diving into the history of RubyCocoa, by Fujimoto Hisakuni. It first emerged in 2001. It provided a bridge between Ruby and Objective-C. Rich is telling us that the first version of the installer wasn’t great – it managed to delete his entire /Library directory. RubyCocoa first shipped with Leopard. Rich is showing us a RubyCocoa Hello World implementation. Wow, it’s really long – about 20 lines. It’s barely visible to people at the back of the room!
Rich is describing the problems with RubyCocoa. First, it’s a bridge. Second, its messaging syntax is different. Third, Ruby uses green threads. Lastly, you ended up with 2 runtimes and 2 garbage collectors, which caused problems. In a nutshell, you could build apps with RubyCocoa, but probably not large, complicated ones.
Then MacRuby hit the scene. MacRuby 0.4 is built on top of Objective-C 2.0 and Ruby 1.9. Every Ruby class/object/method is an Objective-C class/object/method. That’s great, because you get the dynamism of Ruby with the runtime and speed of Objective C: much better than a bridge.
Now we’re seeing a MacRuby implementation of Hello World. Well, it’s still about the same amount of code. There’s still a lot of code around wiring things together and configuring things.
And now, enter HotCocoa. Rich is showing us how to refactor the MacRuby Hello World example into HotCocoa. He’s removing lots of code, bit by bit, and looking more and more like plain Ruby. Actually, it’s looking a but Rails-y in places (e.g.
win = window :title => 'hello world', :frame => [0, 0, 200, 60]
He’s down to 7 lines now of pure Ruby. Rich is telling us how a lot of the excitement around HotCocoa is because of its ability to simplify the configuration of your code.
Rich is giving us a live demo, using HotConsole (available on GitHub), of HotCocoa. HotConsole is written in HotCocoa. He’s running simple Ruby code such as
and how he’s also running code such as
w = window :title => 'hello' b = button :title => 'push me'
Hey presto, a window pops up with a button labeled “push me” on it. Rich gets a round of applause!
Rich is going on to talk about MacRuby 0.5. Over Christmas break, Laurent stargin building a new VM for MacRuby, based on LLVM. He already has a functioning replacement for YARV. Other parts of Ruby 1.9 are being replaced with Objective-C code also (such as the garbage collector and built-ins). The JIT is actually just generating machine code, which means it’s really fast: about 4 to 5 times faster than Ruby 1.9 (the goal is to pass them all). It won’t use any libffi for external calls. It’s passing many RubySpecs already. Laurent is also going to make it fully re-entrant and implement fully concurrent threading. His goal is to automatically generate Grand Central code.
All this could lead to some exciting developments, such as, in Rich’s words, the ability to run Ruby on a “small device that runs OS X on a cellular network” :)
We’re out of time for Rich’s talk. He’s suggesting that you go to macruby.org to learn more.
There’s a gig round of applause as Rich leaves the stage. Break time now!
About the AuthorMore Content by Edward Hieatt