views:

320

answers:

4

I keep running across references to MacRuby and was wondering if any of you have used it for iPhone/Objective C programming.

The MacRuby website says, "the goal of MacRuby to enable the creation of full-fledged Mac OS X applications which do not sacrifice performance in order to enjoy the benefits of using Ruby."

So, my question is: what are the benefits of Ruby?

And, more importantly, what are the limitations?

+5  A: 

I've not used MacRuby, but I doubt if it could be used for iPhone development because it is built on top of the Mac OS X Objective-C runtime and uses the Objective-C 2.0 garbage collector (instead of using its own). Although iPhone OS has Objective-C 2.0, it lacks the garbage collector (you still have to use retain/release-style managed memory), so I expect MacRuby would not work out of the box.

Also, MacRuby would not be useful for developing for the App Store since using interpreters (other than those supplied by Apple) is verboten.

An iPhone port of Ruby might work on a jailbroken phone, but the device has very limited RAM and CPU resources, so I'm not sure how successful such a port would be. I expect MRI is too slow and memory hungry to be useful on the iPhone, but one of the alternative Ruby interpreters might work well - a MacRuby with its own GC perhaps.

I can certainly see MacRuby having many advantages for Mac OS X development. Here are some things off the top of my head:

  1. As a language, Ruby it is a joy to use. Blocks are lovely. It's very dynamic and has great support for meta-programming, making it possible to quickly produce very compact but still readable code.
  2. Objective-C can be quite high-level when it's being Objective, but can get annoyingly low-level when it's being C. Ruby has less of the C-ness.
  3. IMHO, Objective-C has some really weird syntax. You get used to it after a while, but it scares newbies. Ruby has a much more mainstream syntax, especially if you use foo.bar('baz') instead of foo.bar 'baz'.
  4. Objective-C uses header files. I get annoyed cutting'n'pasting method prototypes between .h and .m files. Ruby has none of that.
Will Harris
+2  A: 

MacRuby is really cool, but it still not production ready (even on OS X), and it will not work on iPhone for several reasons:

  1. It uses the Objective C garbage collector, which is not available on the iPhone
  2. It depends on bridge support, which is not available on iPhone
  3. It depends on the LLVM backend, which is awesome, but is not yet production quality for ARM
  4. JITs don't work on the iPhone because of its security model (calls to mprotect() fail in most cases).

I expect over time some of these issues will be resolved, and at some point in the future things like MacRuby will be available on the iPhone, but that is probably several years away at a minimum. If you want to develop for the iPhone now, or foreseeable future, MacRuby is not a realistic option.

Louis Gerbarg
LLVM? ARM? JITs? Would you mind writing out your acronyms for the not so seasoned programmers among us?Thanks!
Jonah
LLVM and ARM are technically acronyms, but they are particular things ("Low Level Virtual Machine" and "Acorn RISC Machine" respectively). Their proper names don't actually give you anything particularly informative about what they do, and I wager most people who use the acronyms don't actually know what they stand for, expanding them probably makes them less clear and certainly makes them less google-able. It would be like writing "United States of America" because people might not know what USA means.
Louis Gerbarg
A: 

You can use Rhodes today

Adam Blum
A: 

The benefits of Ruby are a less obnoxious messaging syntax that's far easier to read and type than tons of nested square brackets and far greater dynamism. The downside is generally execution speed and the way Ruby users tend to gravitate toward overusing its more obscure metaprogramming idioms thereby turning even simple projects into monkey-patched spaghetti.

You're never going to run it on an iPhone unless Apple decides to lift the no-background-processes limitations currently imposed, so if that's all you're interested in, don't bother.

Azeem.Butt