News for hackers. Stuff that matters.
Re:I loved C. But it always fell short for me. Objective-C f... by praptak on Monday November 07, 2011 @03:43AM (#3205490)
Meh. I do not program in Objective-C but I think I can provide more reasons for liking the language than the linked article contains :)

Reason 1: When you need what C provides, it is right there for you (being a superset of C)

Reason 2: When you need what C does not provide (basic reflection, generics, polymorphism, whatever) it is in the "bracket" part of Objective-C.

Reason 3: The two above do work quite well together - the impedance mismatch is minimal, compared to e.g. Python with extensions written in C.

Re:I loved C. But it always fell short for me. Objective-C f... by jballanc on Monday November 07, 2011 @10:43AM (#3206647)
You can actually go one step further with your "Reason 2". Many may not realize this, but everything that you can do with the "bracket" part of Objective-C you can also do with straight-up C and the Objective-C Runtime methods.

This is where I get to promote my favorite page of documentation ever: http://developer.apple.com/library/mac/#documentation/Cocoa/...

Re:I loved C. But it always fell short for me. Objective-C f... by weaksauce on Monday November 07, 2011 @11:21AM (#3206841)
That's an excellent page, thanks!

This actually makes me wonder... how much overhead is in each objective c object over a similar struct in c?

Re:I loved C. But it always fell short for me. Objective-C f... by kstenerud on Monday November 07, 2011 @11:47AM (#3206997)
In terms of size, they're almost the same (Objective-C classes are implemented with structs). In terms of speed, the difference is absolutely huge. You can generate a random number faster than you can make an Objective-C call.

But, it's fast enough for 95% of things people do with it.

Re:I loved C. But it always fell short for me. Objective-C f... by madmoose on Monday November 07, 2011 @04:39PM (#3208287)
Objective-C message sends are not much slower than C++ virtual calls:

http://mikeash.com/pyblog/performance-comparisons-of-common-...

And that's from 2008. Clang's improved it a lot.

Re:I loved C. But it always fell short for me. Objective-C f... by Groxx on Tuesday November 08, 2011 @06:58PM (#3213506)
Actually, that's on an iPhone. Here's the article for OSX from the start of 2008 (two months before your link), where the cached message call comes out faster than the virtual calls, and the non-cached is ~ 4.5x slower instead of ~ 2x on the iPhone:

http://mikeash.com/pyblog/performance-comparisons-of-common-...

Re:I loved C. But it always fell short for me. Objective-C f... by infinite8s on Monday November 07, 2011 @03:06PM (#3207888)
Exactly. Many of the benefits of Obj C's dynamism come into play with the UI, where the main speed constraint is the response time of the user. And whenever you need to write compute bound code it is easy to drop down into C.
Re:I loved C. But it always fell short for me. Objective-C f... by blub on Monday November 07, 2011 @04:27AM (#3205568)
One of these days I will write a detailed account of my experience learning Obj-C, but for now I'll say this:

The fact that Obj-C takes C and adds objects on top is its biggest flaw, just like with C++. Worse than C++ though, Obj-C doesn't even attempt to fix at least some of C's more glaring flaws... you get the whole language, quirks and all.

Re:I loved C. But it always fell short for me. Objective-C f... by chalst on Monday November 07, 2011 @06:25AM (#3205829)
I think it depends on what you want from the language. If you want to write C and gain some safety through the use of the message-passing abstraction, it's perfect. If you want a real high-level language, it's lousy.
Re:I loved C. But it always fell short for me. Objective-C f... by falling on Monday November 07, 2011 @09:09AM (#3206272)
With clang, ObjC is getting very interesting features that take it closer and closer to "real" high level languages, like GCD, ARC and blocks. I'd still like more type safety, but the evolution there is slower and would need more fundamental changes to the language and abandoning C compatibility.
Re:I loved C. But it always fell short for me. Objective-C f... by eropple on Monday November 07, 2011 @11:41AM (#3206956)
I dunno--in an age where we have actual, halfway decent garbage collection, referring to ARC as something that might compete favorably with those "real" high level languages makes my eyes go a bit crossed.
Re:I loved C. But it always fell short for me. Objective-C f... by tptacek on Monday November 07, 2011 @12:20PM (#3207166)
People in 2011 lose weeks to tuning allocators and collectors in real high level languages. C programmers take a memory profile, deploy the appropriate pool/arena allocator, and get on with their job, comfortable with the fact that their former allocation bottleneck is now in the average case register-fast.

ARC fits better with the C world of quickly tuning bottlenecks to register speed. Have you ever debugged C code with custom object lifetimes under a garbage collector? It's a nightmare.

Re:I loved C. But it always fell short for me. Objective-C f... by pvg on Monday November 07, 2011 @04:28PM (#3208253)
People in 2011 lose weeks to tuning allocators and collectors in real high level languages.

But that's, statistically, almost no people out of 'people who use GC'. There aren't that many allocators in common use that even have much in the way of tunable parameters (I can only think of the JVM ones, offhand), the people who spend weeks tuning them have very particular needs - high throughput, low latency, high-enough complexity to warrant a high-level language. These are the sort of people who also do things like start at a PHP page and end up chasing performance improvements in the bowels of a network kernel driver. It's done, but it's unrepresentative.

ARC fits better with the C world

It seems like a much more central reason ARC is more suitable than a GC for Objective C than 'GC tuning is occasionally a dark art'.

Re:I loved C. But it always fell short for me. Objective-C f... by tptacek on Monday November 07, 2011 @04:54PM (#3208336)
What can I tell you here? You're right, of course: most apps don't care about performance at all, either in space efficiency or time efficiency. Those apps shouldn't use C, and should certainly use a GC'd language.

I'm only reacting to the idea that (pp) "because it's 2011, nobody should be using ARC". Well, a statistically tiny number of apps may require the bare-metal performance that hand allocation provides, but they're also disproportionately important apps.

Re:I loved C. But it always fell short for me. Objective-C f... by pvg on Monday November 07, 2011 @06:08PM (#3208595)
Ah, I read it more as 'It's 2011, where's my flying car/why aren't just about all apps running in managed environments'. Sort of like one says, 'It's 2011, why did syslogd just brick my server'. And it's not a completely lisp-machiny, neckbeardy sentiment, 10 odd years ago everyone was telling us the flying car was just around the corner - Apple was busily trying to bridge Java into Rhapsody, Microsoft was working on .NET/CLR. And yet, and yet...
Re:I loved C. But it always fell short for me. Objective-C f... by Flow on Tuesday November 08, 2011 @02:06PM (#3212245)
The last years I thought that Objective-C was perhaps not future-proof enough when MS pushed .Net more and more into being desktop class.

And now MS shows WinRT that is not .Net. Hmmm... :)

Re:I loved C. But it always fell short for me. Objective-C f... by chalst on Monday November 07, 2011 @06:04PM (#3208579)
I think eropple's point was that ARC is not a very high-level sort of approach to GC, i.e., not Lisp-style exact GC.
Re:I loved C. But it always fell short for me. Objective-C f... by eropple on Tuesday November 08, 2011 @01:12PM (#3211940)
That's right (sorry, forgot about this thread). Not saying that ARC is bad, for where it's used--but it doesn't strike me as terribly "high-level".

(Neither, though, does C++, and smart pointers don't help there either. ;) )

Re:I loved C. But it always fell short for me. Objective-C f... by kstenerud on Monday November 07, 2011 @11:49AM (#3207010)
When you're writing for underpowered chips, ARC is a godsend. If you're writing for a mac, there's GC available.
Re:I loved C. But it always fell short for me. Objective-C f... by falling on Monday November 07, 2011 @12:00PM (#3207056)
It shouldn't. GC is not perfect, ARC is not perfect, no language is perfect. All of them can be improved. ObjC is definitely being improved.
Re:I loved C. But it always fell short for me. Objective-C f... by IPlusOneYou on Monday November 07, 2011 @10:06AM (#3206498)
Or you could pick a well thought out OO language like Java or C#, maybe even Python. Unfortunately you're trapped using the abomination for iPhone development unless you pick Monotouch.
Re:I loved C. But it always fell short for me. Objective-C f... by plinkplonk on Monday November 07, 2011 @11:19AM (#3206836)
"well thought out OO language like Java"

Not even Java's fans would defend it as a "well thought out OO" language.

Since this is Hacker News, it maybe appropriate to point out that nothing prevents you from building whatever specific flavour of OO you want on top of the Objective C runtime, if you want it badly enough.

Re:I loved C. But it always fell short for me. Objective-C f... by pnathan on Monday November 07, 2011 @11:59AM (#3207053)
I would not call Python a well-thought out OO language. Its OO is essentially a cranked up dict; the abstraction over the dict is just barely papered over. It can get pretty awkward.