5 ms·
Objective-C, Ruby and Python for Cocoa
- halo 18y agoI 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.
- jmah 18y agoI 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://programming.nu/ http://www.macruby.org/ http://www.macruby.org/
- tptacek 18y agoHe doesn't really present any evidence as to why it works better with ObjC than Ruby, though.
- Hoff 18y agoCocoa meets Javascript: http://cappuccino.org/ http://cappuccino.org/
- tlrobinson 18y agoCappuccino meets Ruby: http://github.com/tlrobinson/cappruby http://github.com/tlrobinson/cappruby It's very incomplete... a proof of concept. The bare bones sample app works, here's the Ruby version: http://github.com/tlrobinson/cappruby/tree/master/TestApp/AppController.rb http://github.com/tlrobinson/cappruby/tree/master/TestApp/Ap... and the original version: http://github.com/tlrobinson/cappruby/tree/master/TestApp/AppController-old.j http://github.com/tlrobinson/cappruby/tree/master/TestApp/Ap...
- protomyth 18y agoMy 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.
- tptacek 18y agoI 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.
- devrieda 18y agoThis is a little bit of an older article and Apple has since been working on MacRuby (http://www.macruby.org/trac/wiki/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
- look_lookatme 18y agoThis is not a special syntax. It's just ruby 1.9 specific hash literal syntax.
- jimbokun 18y agoBut it looks like the important thing is that they have found a way to automatically map this syntax to Objective C method names. EDIT: Or, as the MacRuby docs put it: "MacRuby has a modified version of the parser which detects calls or method definitions using one regular argument, and other arguments using the key/value pair syntax. It will reconstruct the Objective-C full selector if needed. The method name that will be used in the Ruby VM is the same as the Objective-C selector." http://www.macruby.org/trac/wiki/HowDoesMacRubyWork http://www.macruby.org/trac/wiki/HowDoesMacRubyWork
- tptacek 18y agoI'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.
- timburks 18y agoTo 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 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 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 :-) ).
- code_devil 18y agoInteresting read.