Re: Guidance for Cocoa's steep learning curve
Re: Guidance for Cocoa's steep learning curve
- Subject: Re: Guidance for Cocoa's steep learning curve
- From: Jens Alfke <email@hidden>
- Date: Thu, 15 May 2008 12:06:40 -0700
On 15 May '08, at 8:21 AM, colo wrote:
I get messages and oop [Sender Dosomething] or in Ruby
@sender.dosomething. OOP was easy for me as thats how I already
thought code would be like. Of course I am still learning but I fail
to see why Cocoa syntax could be any different than Ruby.
Um, because it's a different language? (Which is, FYI, called
"Objective-C", not "Cocoa".)
Objective-C message syntax is closely based on Smalltalk-80, the
granddaddy* of object-oriented languages. (Ruby is also strongly
Smalltalk-influenced, but in different ways, and ironically its
message syntax is more based on C.)
The idea is that selectors, by intermingling the method name with the
arguments, make the meaning clearer and let you create variant
versions of methods in a simple way.
In Ruby:
obj.useString("bar",true,7) # WTF do all those params mean?
Objective-C:
[obj useString: @"bar" caseSensitive: YES maxLength: 7]; // much
clearer!
Note that you can then add versions of this without the maxLength: and/
or caseSensitive: parameters, or with something else entirely:
[obj useString: @"bar" customTransformer: myTransformer];
which in Ruby would have to be a method called
"useStringWithTransformer" or something like that.
I'll test Macruby when 1.9 comes out, but reading Cocoa is like bash
my head into needless [] : @ syntax every which way.
It usually takes people about one day to get used to the syntax.
Complaining about it just because it isn't what you're used to isn't
very productive.
—Jens
* (as opposed to great-granddaddy Smalltalk-72, and family line
founder Simula)Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden