tags:

views:

1311

answers:

13

I'm a total newbie with Objective-C, and it still seems awkward to me. The mix of Smalltalk-style message passing with C-style function calls seems jarring.

I'm not trying to rag on Objective-C, I really want to know what its fans like about it. Can you help this newb see the light? I'm very familiar with C++ and Python. What are Objective-C's strengths? What do you like about it?

+11  A: 

Objective-C is a little bit more dynamic than C++. I'd say that it's somewhere in between Python and C++. It can be pretty useful for when you want a language as powerful as C but would still benefit from some dynamic typing.

Plus its syntax, while verbose and ugly, really does grow on you (or at least it did for me).

And of course, if you want to program on a Mac, Objective-C is (arguably) the best way to go.

(Although I should point out that I'm not an Objective-C guru)

Jason Baker
+8  A: 

Named parameters are very nice.

[myRect setOriginX: 30.0 y: 50.0];

Paul Croarkin
Parameters aren't actually named. With real named parameters you could change their order. But yes, it's still very nice.
Terry Wilcox
It's actually nicer, because named parameters this way are simpler than real stuff.
Cheery
Cheery: simpler for compiler implementers, or simpler for users of the language? I doubt the latter as it requires that one remember the order of parameters.
Laurence Gonsalves
Simpler for anyone who needs to read the code later - the parameters will always have a consistent order.
Michael Baltaks
Why would anyone care about the order of they're named anyway?
DrJokepu
Point taken, but if someone started mixing [myRect setOrigin x:30.0 y:50.0]; and [myRect setOrigin y:50.0 x:30.0]; just because they could (which they could with real named parameters) I would not consider that a good thing, and therefore while real named parameters have some benefits, there are also potential issues. And I for one am not sure the benefits are worth the potential issues.
Michael Baltaks
Those are not real named params, just syntax sugar - or should i say syntax dust in the eyes - it's arguably "better" spelling of `myRect.setOriginX_y(30.0, 50.0)`
Nas Banov
+3  A: 

It's not my first choice when picking a language to do a project in, but Objective-C does have some great features that make it fun:

  • It's a pretty thin object-oriented layer on top of C, which means C programmers can learn it in less than a day
  • It's a dynamic language, which makes writing certain kinds of extensible systems a little simpler (check out Cocoa's use of duck typing for delegate classes, for instance)
  • It's very introspectable -- for example, you can extend the definition of methods at runtime, allowing for before/after/around hooks on methods
  • It's getting closures
  • Xcode/Interface Builder are so good they make me forget my preference for good text editors, especially when working closely with designers

Of course, if you're writing an iPhone app, you don't have a choice of which language to use. I think a good amount of the raves for Obj-C come from the fact that if you're going to be forced to use a language, Obj-C is a lot more palatable than some other languages.

Justin Weiss
The point about C programmers learning it in less than a day is kind of exaggerated. I've been writing C for years and I'm currently working on an entirely Objective-C project. My partner and I are still looking up the more advanced concepts daily after a little under a month on the project.
Brian Gianforcaro
Are you talking about the language itself or the Cocoa libraries? I found the language itself to be pretty intuitive and simple, but there's a huge range in quality between the Cocoa libraries, so I do have to have documentation up pretty regularly.
Justin Weiss
+1 except for "Xcode are so good". Xcode makes me want to poke out my eyes.
Frank Shearar
A: 

It C with OO love.

  • Single inheritance, Named params
  • Messaging support Garbage collection
  • (2.0) Plus a great set of base classes in the form of the NextStep libs
  • Lastly XCode takes a lot of the pain out of it.
Jonathan
+2  A: 

I've found that over time Objective-C has really grown on me, but then I've always done a lot of programming in C. As others have stated already, the smalltalk-style syntax was a bit strange at first, but now I find that I actually like it... I think the fact that the parameters are labeled makes it a lot easier to sit down with unfamiliar code and get a good idea about what's going on very quickly.

I also like how dynamic the runtime system is for Objective-C. I found that it was simple and easy to pick up right away if you know C already, unlike C++ which takes a little longer to really get a handle on and a lot longer to truly master.

Jason Coco
A: 

I'm not a fan of the syntax, but you get used to it, and as Paul Croarkin pointed out, named parameters are indeed nice.

On the other hand, I think C++ can be used to scare little children, so we're left with Objective-C and C# as the OO languages derived from C. I think they're both great languages.

Last but not least, Xcode. I think it's one of the very best IDEs out there. Without Xcode, it would have taken me much longer to learn Objective-C.

Can Berk Güder
C++ can also scare grown-ups!
DarenW
A: 

Back on NexTStep....

There is some value in objects passing messages between zones. This was the ObjC default in NeXT and made for amazing reliability.

Zones

Each object is in a different memory protection space. ( by default)

There is a small performance hit.

But my C code in this object can't mung the c-code in that object. Tends to find memory stomping bugs during development, instead of after deployed.

Tim Williscroft
This is completely incorrect. Zones were in the same address space on Nextstep (as they still are on OS X), they were purely used for managing memory locality, and occasionally for cleanup optimizations. You are conflating zones with distributed objects, which are very different things.
Louis Gerbarg
+1  A: 

(A little bit off-topic, but may be of interest to the OP/readers)

If you are a Pythonista, you can code Cocoa apps in pure Python. The method and class names are (almost) identical, so you can just use the Obj-C documentation. Wherever you see a method that is name:

[object doThing: thing with: otherThing];

then you can translate it into:

object.doThing_with_(thing, otherThing)

Most useful types are mapped directly onto python objects, but there are some times where weird things happen.

Matthew Schinckel
A: 

The quality of the frameworks/libraries (Cocoa, OpenStep) is much better than that for java and c#. c++ has other problems. The syntax is of course nto as nice as Smalltalk, but it is a very successfull mixture of high- and low-level constructs. It offers less choice than c++, which is a major advantage.

Stephan Eggermont
+3  A: 

Dan Ingalls, one of the leading developpers on Smalltalk, said that Objective-C would be a much better objectification of C than C++. The language is multi-paradigm, so everyone can get along there. And it is really not only the language: XCode is a lot of fun and .nib files are just so much smarter than the Java way of building User interfaces.

A language is good if it lets you get your stuff done and Objective-C doesn't get into your way often. Want to use the cool new multi-CPU extensions in GCC? You can! Want more sophisticated programming complete with a garbage collector? It's there! It's a good language for most native programming needs; that is what's good about it.

nes1983
Well, sure! Objective-C was inspired by Smalltalk's object model, and C++'s version of OO was inspired by Simula.
Ben Karel
+3  A: 

It's OO in C well done.

Friedrich
+3  A: 

IMHO Nothing!

Objective-C is just an unreadable sintax coding horror pushed up in the code languages market by iPhone, since Obj-C is the only programming language for that 'evil' machine.

Once iPhone will disappear or embrace a new better programming language, Obj-C will then disappear instantly.

Marco Demajo
A: 

I love "Categories" in Objective C, which allows me to extend ANY class.

Also the performSelector and the ability to pass any message to anything, increases productivity, but of course make the code a little bad.

Also the reflection level supported, where I can convert from String to Class and vice versa. All of this at the same time, the fact that the language doesn't run on the VM.

Also I sometimes feel Memory management system with release/retain along with a necessary autorelease is nice. But not always.

And of course I do hate the language for a lot of reason which is not the question, so leaving that off.

Quakeboy