views:

287

answers:

4

I have managed to avoid C and C++ up until now (except for a few HelloWorlds), and have instead worked in higher-level languages. I've worked and lived in VB6, then Java, then C#, then ActionScript, and now Ruby.

I've recently become curious about programming for the IPod Touch/IPhone. Though I've seen some possibilities for avoiding ObjectiveC (like Mono for IPhone), I'm curious about Objective C. Mostly: does it require the developer to handle garbage collection and manage pointers and that sort of thing?

Edit: I am totally open to the possibility that my concept of higher- and lower-level languages is incorrect or misleading.

+1  A: 

"Mostly: does it require the developer to handle garbage collection and manage pointers and that sort of thing?" - on the iPhone, yes.

Cade Roux
Isn't that quite difficult, technically?
Yar
Slightly better than C, nowhere near as productive as C#. A bigger issue is the lack of compile-time checking on method invocations because of the message passing method mechanism - a very late binding.
Cade Roux
The Objective-C compiler will generate a *warning* if you attempt to call an undefined method. Ignore these warnings (as with all others) at your peril. Asking the compiler to treat these warnings as errors gives you more strict checking. Of course, in Objective-C dynamic method dispatch allows you to call a method that wasn't defined at compile time--a huge advantage of dynamic languages such as Objective-C, Python, Ruby, etc.
Barry Wark
And this is a great reason to compile with -Wall -Werror
nall
And suddenly we're back to a dynamic vs. static languages :).... thanks for this one Cade, adds another aspect I hadn't thought about. But after six months of Ruby, no checking of anything becomes quite normal. No less annoying, though...
Yar
I don't think it's THAT dynamic! And you don't have to call things that way...
Cade Roux
+4  A: 

There is garbage collection for Objective-C but not for the iPhone, i. e. if you write software for the iPhone you have to handle the memory stuff on your own, but this is no general Objective-C problem.

arno
It's worth keeping in mind that even without garbage collection, memory management is quite a bit simpler in Objective-C than plain C or C++. Apple has some very simple rules for object ownership, and if you follow those, you're pretty much guaranteed to be managing your memory correctly.
Chuck
Thanks Chuck, that makes sense. I've always felt that automatic garbage collection was hard enough for people to understand, since memory leaks are still possible.
Yar
+1  A: 

It's not as "high-level" as C# and Java, IMO, but it's still considered a high-level language, just like C++ and, yes, C.

Objective C does have garbage collection, but the iPhone Object C does not.

Randolpho
Ok re: high-level. Doesn't the lack of garbage collection mean a lot more work for the developer?
Yar
not a lot more work. if you follow apple's guidelines for memory management, that should take care of 90% of cases. do it enough and it's more just something you do out of habit than the notion of the drudgery of memory management like it is in C.
pxl
I would argue that Objective-C's object-orientation is at a higher level than either C# or Java (e.g., the Java equivalent of `[self performSelector:foo afterDelay:2]` is quite a bit longer). But the C parts of Objective-C are much lower-level, of course — it's C!
Chuck
Interesting, thanks everybody for this stuff... quite interesting.
Yar
+8  A: 

Garbage collection: yes, but not nearly as bad as C or C++. Once you understand Objective-C garbage collection it's really easy. It doesn't take that long to learn or master either.

As far as pointers go - you'll be using pointers far less frequently than you would in C or C++. Yes, a bit of knowledge about pointers is useful (knowing the difference between declaring NSString * and NSString) but that's also not that complicated.

Personally I would avoid all the "higher-level" languages that are emerging for iPhone development. They really only eliminate the need for you to learn Objective-C but still force you to use the native framework (Cocoa Touch). They add complexity for laziness sake. Objective-C can be learnt in a week, debugging framework nuances takes a lot longer. But then again, it is only my opinion.

edit:

C# memory management can also be a pain if not done correctly. Yes, there's a garbage collector that works in a lot of cases. However, there are also objects that need to be disposed and not disposing them correctly can lead to memory leaks. Creating your own IDisposable objects can also be tricky if you're not 100% sure what the order of the Disposing sequence is. I've seen a lot of projects where developers get this horribly wrong. Basically what I'm saying is that the Objective-C memory management is not more complex or more technically difficult than the Dispose chain in C#/.NET

rein
+1 thanks so much especially for the last paragraph. I'll keep this all in mind.
Yar
Thanks for the edit: I actually said that in one of the comments below, basically. If you don't release your object references correctly, the GC cannot do its work in any case, automatically or not.
Yar