News for hackers. Stuff that matters.
Re:C++ 11 Approved by sjwright on Saturday August 13, 2011 @06:28AM (#2880726)
I think you might be grossly overestimating the performance penalty of Objective C's dynamic behaviours and message passing. I did too when I started programming with it, but then I did some quick benchmarking and realised the penalty was negligible bordering on nil.

For big loops, be comforted in knowing that message passing is aggressively cached; the second and subsequent calls are barely slower than a C method call.

And for those insanely big loops, with methodForSelector: you can bypass message passing entirely and call the method directly... you speed freak.

Re:C++ 11 Approved by sorbits on Saturday August 13, 2011 @08:38AM (#2880847)
C++ is used in environments where every byte and cycle counts, regardless of your personal experience, run-time meta data (and going via lookup tables) does have a big measurable overhead that many prefer to avoid.

Adding to that, the things a C++ compiler can do at compile time (via static typing and full knowledge of the types) is pretty convenient and impressive, relying on these things to be done at run-time is often complex and/or require more code to be written by the programmer.

Re:C++ 11 Approved by leon_ on Saturday August 13, 2011 @09:06AM (#2880891)
In an environment where every byte and cycle counts I'd be using C. C++ has too much stuff going on behind the scenes. (Like hidden object copies, potentially bloated operators, etc.).

If you can live with enabled exception handling (which is a performance toll) then some additional object meta data shouldn't be a problem.

Re:C++ 11 Approved by copper on Saturday August 13, 2011 @09:54AM (#2880951)
> C++ has too much stuff going on behind the scenes. (Like hidden object copies, potentially bloated operators, etc.).

The thing is, C++ is usually good about not charging you for features you don't use - and with the reasonably good debugging and profiling tools, most of the problems you mention above are fixable to get performance that is close (or equal) to C, with maybe better maintainability.

To pick a not-so-random example of something that's difficult to implement in C as safely as in C++, see expression templates[1]. I'd be interested in something similar to what eigen does written in C. (Of course, the last time I did this minibenchmark, so-and-so's lapack library was still slightly faster than eigen :)

The bottom-line, perhaps, is that if I'm writing a library, I'd do it in C simply because it's self-contained and has a nicely limited scope, and as a bonus is usable from oh-so-many other languages. If I'm writing an application that really, really requires serious performance, I'd prefer to use C++.

[1] http://en.wikipedia.org/wiki/Expression_templates

Re:C++ 11 Approved by SamReidHughes on Saturday August 13, 2011 @02:14PM (#2881563)
It's very easy to avoid at least the problems you've mentioned by not making copyable objects and not defining bloated operators.
Re:C++ 11 Approved by leon_ on Sunday August 14, 2011 @06:26AM (#2883320)
> not defining bloated operators

Can you guarantee that for every 3rd party lib you use?

Re:C++ 11 Approved by dkersten on Sunday August 14, 2011 @07:55PM (#2884871)
Then only use the ones that do guarantee this. You can also make use of C libraries, but still have access to some nice C++ features for your code.

Since C++ lets you omit language features until you basically have plain C, you get to choose what level of support you can live with.

Re:C++ 11 Approved by SamReidHughes on Sunday August 14, 2011 @04:14PM (#2884339)
Who cares about theoretical possibilities? The reality is that hidden object copies and bloated operators are not a real problem.
Re:C++ 11 Approved by pmarin on Saturday August 13, 2011 @07:06AM (#2880754)
Have you replied the wrong thread? I was not talking about message passing.
Re:C++ 11 Approved by stopmi on Saturday August 13, 2011 @07:44AM (#2880795)
maybe because reflection/introspection is done via "Objective C's dynamic behaviours and message passing"?
Re:C++ 11 Approved by leon_ on Saturday August 13, 2011 @09:14AM (#2880909)
Actually these are only convenience methods.

For example to get a class name you can either use [object className]. Or you can use object_getClassName()/directly access "anObject->class_pointer->name" without dispatching any messages. The same goes for any other runtime attribute of an object.