Live data from Hacker News

Objective-C, Ruby and Python for Cocoa

theocacao.com

1–10 of 26 posts

Re: Objective-C, Ruby and Python for Cocoa

#2
I think this may be validation of Microsoft's approach with the .NET platform since one its core conclusions seems to be that Cocoa is too closely coupled to Objective-C to make alternative dynamic languages attractive as they don't "fit together nicely". The other line of discussion it goes down is whether or not Objective-C is the best option, but that's always going to end up being a matter of taste.

Re: Objective-C, Ruby and Python for Cocoa

#4
My biggest problem with Ruby for Cocoa work is that I enjoy the Smalltalk message passing syntax (keyword) more than the C++ syntax (object.name). The hacks to make it work right in Ruby do not look quite right.

Objective-C fills the place C++ or C# fill in the .NET platform world. It would be interesting to see a language built for Cocoa that fills the VB role.

Re: Objective-C, Ruby and Python for Cocoa

#5
This is a little bit of an older article and Apple has since been working on MacRuby (http://www.macruby.org/trac/wiki/MacRuby) which is poised to replace RubyCocoa. MacRuby adds a special syntax to Ruby to better deal with the keyed arguments. From the docs:

Objective-C:

  NSWindow *window = [[NSWindow alloc] 
      initWithContentRect:frame 
      styleMask:NSBorderlessWindowMask 
      backing:NSBackingStoreBuffered 
      defer:false];
RubyCocoa:

  window = NSWindow.alloc.initWithContentRect_styleMask_backing_defer(
      frame,
      NSBorderlessWindowMask,
      NSBackingStoreBuffered,
      false)
MacRuby:

  window = NSWindow.alloc.initWithContentRect frame, 
      styleMask:NSBorderlessWindowMask,
      backing:NSBackingStoreBuffered,
      defer:false

Re: Objective-C, Ruby and Python for Cocoa

#6
post #2

I think this may be validation of Microsoft's approach with the .NET platform since one its core conclusions seems to be that Cocoa is too closely coupled to Objective-C to make alternative dynamic languages attractive as they don't "fit together nicely". The other line of discussion it goes down is whether or not Objective-C is the best option, but that's always going to end up being a matter of taste.

I don't think he's passing judgment, saying that Cocoa is too closely coupled, I think he's just comparing why it works better with Objective-C than with Ruby. Amongst other interesting projects are Nu, a Lisp designed for Cocoa and Objective-C; and MacRuby, a fork of Ruby that uses Objective-C's runtime and garbage collector, and language tweaks for named arguments.

http://programming.nu/

http://www.macruby.org/

Re: Objective-C, Ruby and Python for Cocoa

#7
I'm doing a bunch of work in Ruby/Cocoa right now and I am having no problems. Highly recommended. Thoughts:

(1)

ObjC syntax is clearly clunkier than Ruby syntax; you can't honestly compare the two languages without noting that Ruby has arrays and tables as first-class citizens, and ObjC has them only as libraries. You could stop right there; your ObjC code is littered with "dict.objectForKey" and "dict.setObjectForKey" calls, and your Ruby code isn't.

The keyword argument bridge syntax turned me off too, but the reality is that 80% of the pain is due to Cocoa's incredibly verbose method names; for instance:

OSX::NSColor.colorWithCalibratedHue:saturation:brightness:alpha

(2)

You can turn garbage collection on in 10.5 ObjC projects, but it isn't recommended; you lose 10.4 compatibility, and allegedly take a performance hit. The Ruby/Cocoa bridge handles retain/release counts automatically.

(3)

Ruby can call into C/C++ code too; there are multiple FFIs (I've done a lot of work with Ruby/DL) and if you're going to suck it up and write C code wrappers anyways, like you would be in ObjC, you can just write a Ruby extension.

(4)

This argument about "OSX revolves around Cocoa and Cocoa revolves around ObjC" is just emotional. What's the thing you can do in ObjC that you can't do in a Ruby/Cocoa project? Ruby/Cocoa can access arbitrary ObjC objects, open them up and redefine methods, or subclass them. In the unlikely event that I find something that doesn't work in Ruby, then I'll go write the 20 lines of ObjC required to make it work, and call into it from Ruby.

It's 2009. We shouldn't be writing application code directly in C anymore.

Re: Objective-C, Ruby and Python for Cocoa

#8
post #6
post #2

I think this may be validation of Microsoft's approach with the .NET platform since one its core conclusions seems to be that Cocoa is too closely coupled to Objective-C to make alternative dynamic languages attractive as they don't "fit together nicely". The other line of discussion it goes down is whether or not Objective-C is the best option, but that's always going to end up being a matter of taste.

I don't think he's passing judgment, saying that Cocoa is too closely coupled, I think he's just comparing why it works better with Objective-C than with Ruby. Amongst other interesting projects are Nu, a Lisp designed for Cocoa and Objective-C; and MacRuby, a fork of Ruby that uses Objective-C's runtime and garbage collector, and language tweaks for named arguments. http://programming.nu/ http://www.macruby.org/

He doesn't really present any evidence as to why it works better with ObjC than Ruby, though.

Re: Objective-C, Ruby and Python for Cocoa

#9

My biggest problem with Ruby for Cocoa work is that I enjoy the Smalltalk message passing syntax (keyword) more than the C++ syntax (object.name). The hacks to make it work right in Ruby do not look quite right. Objective-C fills the place C++ or C# fill in the .NET platform world. It would be interesting to see a language built for Cocoa that fills the VB role.

I had the same reaction, but ObjC's method names are so bad that I just wound up writing my own Ruby wrappers anyhow, so most of my code is written in Ruby idiom.

ObjC does not fill the role C# fills in .NET. ObjC is still C code. C# doesn't have pointers. It doesn't segfault. Every object has reflection. There aren't aliasing problems. ObjC fills the place C++ fills in Win32; we still need a C# replacement.

Re: Objective-C, Ruby and Python for Cocoa

#10
post #7

I'm doing a bunch of work in Ruby/Cocoa right now and I am having no problems. Highly recommended. Thoughts: (1) ObjC syntax is clearly clunkier than Ruby syntax; you can't honestly compare the two languages without noting that Ruby has arrays and tables as first-class citizens, and ObjC has them only as libraries. You could stop right there; your ObjC code is littered with "dict.objectForKey" and "dict.setObjectForK…

To be fair, it depends on the application. You might not have to write them, but there are still plenty of applications where memory and speed are issues, and C gives you some really good tools to deal with them, but you're right -- C is not a high level language and shouldn't be used as one. I would go a step further and say that Objective-C also is not a high level language. Most people here would agree, but lots of Cocoa developers see it as the top of their language stack.

When you get serious with it, the Ruby/Objective-C combination has a lot of problems, mainly because the two languages and cultures simply weren't designed to go together. I have some notes on that here http://programming.nu/rubycocoa-and-rubyobjc and if you have the patience, a talk online that I presented at Jonathan Rentzsch's C4[1] conference: http://www.viddler.com/explore/rentzsch/videos/13 MacRuby is a step in the right direction, but in my opinion it's better to use a glue language that's specifically designed for the task (and if you don't like mine, write your own :-) ).

Post reply on HN