Phusion white papers Phusion overview

Phusion Blog

Objective-C for Ruby developers, un not-so-petit interlude (1/2)

By Jean Pierre Hernandez on March 24th, 2010

Bonjour les amis! Welcome back to to this second installment of our tour de MacRuby! In the previous article, we went over the basics of XCode and Interface Builder. With this preliminary knowledge, we were quickly able to write our very first Cocoa application using MacRuby as well as understand the importance of Camembert!

Indeed, that was quite an interesting experience as it showed not only how easy it was, but hopefully, it also showed how fun this was as well. If I’ve been unable to convince you of this in the last article, I certainly hope I will be able to do so in this article as we will compare the MacRuby way with the traditional “Objective-C” way.

Assuming you are already well familiar with Ruby, it’s important to go over some basics of Objective-C seeing as Cocoa and its documentation assume this language. Basic understanding of Objective-C is therefore a must when it comes to developing Cocoa applications.

At a first glance, Objective-C and Ruby couldn’t be more different from each other than humanly possible. Where Ruby is beautiful and elegant, Objective-C seems to be convoluted with square brackets. Looking past the syntactic differences though, you’ll be able to see that they really don’t differ that much from one another.

For instance, both Objective-C and Ruby are strongly typed object oriented programming languages. They both support dynamic dispatching via message dispatching, i.e. objects being able to respond to messages and effectively run the corresponding code for that message during runtime.

Realizing these similarities, Laurent Sansonetti — black-belt Patrick Hernandez imitator at Apple Inc. — set out to unify these two worlds, resulting in MacRuby. With MacRuby one can access the Cocoa library as if it were an integral part of Ruby itself. This in contrast to RubyCocoa which acts as a bridge between Ruby and Cocoa.
Read on…

Creating our very first Mac application with Ruby, how exciting!

By Jean Pierre Hernandez on March 12th, 2010

People always ask me why I never find a programming language for the Mac and settle down down down. C’est absolument incroyable indeed as the answer should be pretty straight forward to those who have already written an application for the Mac using Objective-C.

As a matter of fact, in France, raising such a question is like asking whether or not Camembert goes well with French fries or not. The answer to this question is obvious as it’s a known fact that Camembert goes well with everything. Seeing as not everyone is blessed with a taste for fine French cuisine and/or is from French héritage however, I’ll try to give an approximation in this blog.


Read on…

A gentle introduction to MacRuby

By Jean Pierre Hernandez on March 12th, 2010

Bonjour les amis! My name is Jean Pierre Hernandez, I work at Phusion and indeed, am a direct relative of legendary super star disco god Patrick Hernandez.

Where Patrick was born to do disco, I was born to dabble in code, in particular with Cocoa. My brother would often use a cane to emphasize his graceful dance moves, and following suit, we’ll use Ruby to emphasize our élégance and love for fine Mac application development.

It brings me enormous joy to have you here on my blog, most likely resulting from a latent hate [[[towards] angular] brackets]. That’s okay, we’ve all been there, the important thing is we’ve found out that this torture is absolutement not necessary and that verbosity and masochism are still choices when it comes to developing delicious Mac applications. Not here however, as we’ll settle with no less than élégance and beauty! Painlessly incroyable indeed!

Before we’re able to start cooking on our first of many delicious Mac applications, we first need to set up the environment where all the magic happens.

As elegant and beautiful as MacRuby may appear to the developer, make no mistake, it’s also a beast when it comes to performance. Via techniques such as Just-in-Time (JIT) and ahead-of-time compilation, MacRuby applications can achieve performance comparable to native applications. Ahead-of-time compilation in particular is useful if you would like to keep your delicious mac recipes private to a larger extend.

In order to achieve all this goodness, MacRuby employs one of the most sophisticated compiler infrastructures at this moment in the form of LLVM. Depending on your needs and intentions with MacRuby you may want to choose to compile all these components from source by grabbing it from SVN or Git. Keep in mind that in the case of the latter, LLVM is still a moving target in terms of releases and is subjected to rapid API and feature changes. It is for this reason that MacRuby is forced to use specific builds as specified in the README.

Compiling LLVM and MacRuby from source can be quite time consuming and tedious. In particular, LLVM will take about 1 hour to compile utilizing both CPU cores on a unibody MacBook Pro. Luckily, our community is blessed with nice people who made sure we could also utilize already-compiled binaries and nightlies, the latter containing nightly edge builds of MacRuby. For the sake of stability, we’d recommend you to use the former instead.

Once you’ve installed these components, we can start cooking up our first cocoa application for the mac using Ruby, which is exciting indeed!