views:

2337

answers:

10

I do mostly ActionScript development, plus a bit of C# (and historically Lingo, Java and VB). What are my chances of learning Objective-C? I'd love to have a go at iPhone development, but the language just looks so insanely different to everything else.

+4  A: 

You have a shot at learning anything you put your mind too, don't hold yourself back.

FlySwat
+6  A: 

Chance of learning = Directly proportional to the amount of time you're willing to spend on it.

More prosaically, sure. It'll be very different to that which you've done before, but programming is really just the logical arrangement of thought. If you can do that in C#, you can do it in Objective C - the specifics of memory management, Cocoa APIs, and the underlying C language are not that different. The only real leap will be pointers, the argument being that some people "just can't get" them. I don't buy this - there's a lot of material out there on it, and if you're willing to put the effort in then I can't see any reason why you couldn't.

This said, I'm of the school that "Anyone can learn anything", if they're willing to put the effort in. It might take one person 2 days, and another 20 years, but you can get there if you wish.

Adam Wright
+2  A: 

Of course you have a shot.

The hurdles for you will likely be memory management and understanding pointers. Objective-C looks wild at first but after a bit of work you will find it pleasantly intuitive.

Memory management might not be an issue if you stick to apps targeted at OS X as Objective-C 2.0 introduce garbage collection, however do be aware that iPhone development does not support garbage collection.

hunterjrj
+1  A: 

Objective-C isn't that complicated — the syntax is exactly like C (that is, similar to ActionScript and C#) with the addition of message sending brackets.

Once you learn those, you'll have the language down.

Learning the large standard library is a long process, but easier than learning, say, Swing.

Give it a shot — what's the worst that can happen?

Rich
+3  A: 

Definitely. If you already have the OOP paradigm understood, it will be just a matter to get used to the libraries.

Most of the syntax will be familiar for you very fast, since is an small language, it does not have many reserved words. So as long as you get used to invoke a method like:

[object method:arg1 with:arg2];

Everything will be ok.

As I said , the most difficult to learn is th platform API, but the only way to get it is by practicing

OscarRyz
Thanks for the supportive words, but that function is just mad looking! what does it mean! which is the return type and which the input! I just see square brackets as arrays!
Iain
yes.. That is the most challenging part. But it takes some minutes to change your perspective. I'll add an answer on this, give me a minute.
OscarRyz
+7  A: 

If you are good at C# and Java, you will have no problem learning Objective-C. Objective-C is much easier to learn than C++. The syntax is pretty simple and most of it is C (the C syntax is pretty similar to C# and Java).

Actually this simple tutorial teaches you the basics in a couple of minutes ;-)

I fail to see what is so hard about it. When you look at this Java code

someObject.toString();

Objective-C is simply

[someObject toString];

Or when you have Java code:

someObject.someMethod(x, y);

Obj-C code could look like this

[someObject someMethodWithX:x andY:y];
Mecki
Wow, I didn't know Objective-C was so ugly. Give me good old Java syntax any day. ;)
JavadocMD
yup... that looks preety ugly
Pablo Marambio
Nahhh is not that ugly. Let's say it is just "different" :)
OscarRyz
I find it rather elegant, as parameters to messages are named, making code more readable.
Paul Dixon
A: 

How much do you want to learn it? That's all that matters. Clearly from your post you have the aptitude to write code in it. I suspect if you give it a week or two, you'll find that you're "getting it".

There is a TON of resources out there for Cocoa development and I've found the Apple development community to be very friendly and helpful. I'm with Adam on this one - you can do ANYTHING you put your mind to!

Best of luck!

itsmatt
+36  A: 

Brief history of the "square brackets" is I remember it.

One of the most challenging aspects of the language are the square brackets because they look like arrays, as you just mention.

As I remember the language was inspired in smalltalk, but using C to gain speed.

The idea behind smalltalk was to send message as we do with real life objects. For instance if I ask you your age I would say something like this in natural language:

iain what is your age?

And in smalltalk:

iain whatIsYourAge

In smalltalk everything is an object, thus you can send the following message to the number 5.

5 factorial

Well.. to make the parser faster and easier to understand in Objective-C messages where enclosed in square brackets.

[iain whatIsYourAge];

Which has the same meaning as functions or methods in "dot" languages like Java, C# and C++

iain.whatIsYourAge();

But I guess they did not though about messages as functions, but something more "natural". Today we are so used to the "dot" and the "()" syntax, that we don't even notice how "unatural" they are anymore..

The methods in Objective-C can also return values, and also receive parameters in their arguments.

For instance assuming we are still working with iain as an object, the following Java:

Broom broom = new Broom();
Date now = new Date();
iain.cleanYourRoomUsing( now, broom );

Would be more natural in Objective-C

// Note I haven't use Objective-C in 10 yrs. So I don't really remember how to create a new Object,
// but let's asume it is like this.. just for the sake of the example.
Broom* aBroom = [Broom newOne]; 
Date*  now = [Date newOne];

[iain cleanYourRoom:now andUseThe:broom];

Of course you can also put them in the same line

// "dot" languages java, c++, c#
iain.cleanYourRoom( new Date() , new Broom() );

//Objective-C
[iain cleanYourRoom:[Date newOne] andUseThe:[Broom newOne]];

And that's pretty much it. The idea behind Obj-C was to do what smalltalk did, but a lot faster.

The declarations changes of course , but the idea is not too different.

It was something like:

@implementation Man : Person 

- ( void ) cleanYourRoom: Date* when, andUseThe: Broom* what
{
   [self yeahSure];
   etc...
}
@end

It would be the "equivalent of "

class Man extends Person {
   public void cleanYourRoom( Date when, Broom what ){
       this.yeahSure();
       etc...
    }
}

I learn Objective-C some 10 yrs ago, using WebObjects on Mac OS X server ( based on NextStep ), so this is not at tutorial at all, there are plenty of resources for that. But instead is a brief history of the "square brackets" and I hope it helps to understand them better.

Please feel free to modify this comment to make it "Objective-C" valid :P

OscarRyz
Wow, what a tempting language you've made Objective C sound! Well written. Thanks.
defmeta
As an assist towards making it more Obj-C valid, we'd usually useaBroom = [[Broom alloc] init]; to allocate and initialize a new Broom. Or, if you need to provide a parameter, aBroom = [[Broom alloc] initWithHandleLenthInFeet:6];
Lawrence Johnston
@Oscar Reyes, thanks for the great explanation.But, I think you forgot the embrace the types in cleanYourRoom: Date* when, andUseThe: Broom* what , (Date*) (Broom*) . this is acceptable, after all you haven't used this language for 10 years :)
Comptrol
A: 

Objective-C isn't difficult per-se however Apple's XCode's autocompletion is poor for function call autocompletion. So its not a fundamental issue with the language, but more of an issue with ME not knowing the API. I picked up Objective-C in an hour and feel the language has lots of potential, especially to write multithreaded code, but I still struggle trying to remember function calls and how the API works (so I have to spend have my time wading through documentation). All because XCode's autocompletion sucks.

So I can't blame the language, its actually kind of Cool, and I love learning new languages, but I do blame the tools.

Robert Gould
A: 

If you've been programming long enough, you should be to the point where you understand that any language is just another variant of the same abstract tool, one which you've already been using for months or years to build things. The challenge isn't in learning a new way of thinking (entirely), but rather just learning how to use a different tool, one which is better suited for the job at hand, but may be odd at first glance (like Obj-C and the square brackets).

Honestly, if you can grasp major OO concepts and have some experience with a C-derived language, you really should be able to pick up Objective-C. Yes, the square brackets can be a bit daunting at first, but you should never let superficial language differences get in the way of your quest to learn them. Lisp looks crazy, but you should still learn it, too.

So yes, learn Objective-C and Cocoa Touch. Just, whatever you do, do not try to sell another flashlight/tip calculator/breakout clone. Write anything you want to learn, fine: if you try to post it to the App Store, your development rights will be revoked. (Kidding... but if wishes were horses...)

Update

Since I can't yet comment (still waiting on 50+ rep), I'm editing this answer because I felt it necessary to address a line in the currently-accepted answer:

Which has the same meaning as functions or methods in "dot" languages like Java, C# and C++

Not entirely. Objective-C started out as a set of pre-processor macros that translated the syntax into plain C: this means, of course, that passing a message to an Objective-C object is translated into a straight C function call (to objc_msgSend, specifically); a call, mind you, that has no notion of which "object" it "belongs" to. In languages like Java and C++, calling a method on an object requires the runtime to inspect the object's v-table or similar to look up the proper function pointer to be called.

This is all a bit of technical gobbledegook until you consider the implications: in other languages, attempting to call a method on an object that is NULL will blow everything up, because you're attempting to look up function routing information in memory that is no longer valid.

But in Objective-C, you can send messages to NULL (or 'nil') to your heart's content with no problem. Makes things like this example "safe":

id someObj = [[someObj alloc] init];
// assume this method releases its argument, someObj
[someOtherObj doSomethingAndRelease:someObj];  
someObj = nil;
...
[someObj someSelector]; // oops, we forgot this is nil, but no matter!

(Note I say "safe": it isn't good practice, but it will work.)

And why does this work? Because the message send is just being translated to a call to objc_msgSend(), which is (essentially) a no-op if given a nil object.

This language is neat-o!

rpj
How did you know about my flashlight idea?
Iain