Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Objective-C++ language: where can I find more information about it?

I've been learning C++ for some months now and find it an excellent language albeit its perks.

I was wondering what exactly is the so-called Objective-C++ and if it's worth learning it as a main development language to target Apple environments (ie. Mac OS X, iPhone OS). Searching around the web I only found a couple of good articles: mainly Wikipedia's entry and one from Mac Dev Center.

Wikipedia says:

Objective-C++ is a front-end to the GNU Compiler Collection which can compile source files which use a combination of C++ and Objective-C syntax. Objective-C++ adds to C++ the extensions Objective-C adds to C.

The Mac Dev Center article adds:

Apple’s Objective-C compiler allows you to freely mix C++ and Objective-C code in the same source file. This Objective-C/C++ language hybrid is called Objective-C++. With it you can make use of existing C++ libraries from your Objective-C applications.

The Apple article calls Objective-C++ a language. Is this right?

I would like to know the following:

  • Is it possible to learn and use Objective-C++ without knowing C/Objective-C?
  • Are there any good books, sites, forums, etc where one can get more information and/or help?
  • Are there any big projects done in Objective-C++ as far as you know of?
like image 240
Kensai Avatar asked Jan 22 '10 12:01

Kensai


People also ask

Where did Objective-C come from?

Objective-C was created primarily by Brad Cox and Tom Love in the early 1980s at their company Productivity Products International (PPI). Leading up to the creation of their company, both had been introduced to Smalltalk while at ITT Corporation's Programming Technology Center in 1981.

Where is Objective-C used?

Objective-C is general-purpose language that is developed on top of C Programming language by adding features of Small Talk programming language making it an object-oriented language. It is primarily used in developing iOS and Mac OS X operating systems as well as its applications.

What is the main objective of C?

Objective-C is the programming language that is used to write applications for Apple's iOS and OS X operating systems. The Objective-C programming language is based on C, but it adds support for object-oriented programming. All Objective-C programming is done with the Foundation framework.

Is Objective-C still used today?

While Objective-C is still supported by Apple and will likely not be deprecated anytime soon, there will be no updates to the language. Objective-C is as good as it's ever going to get.


2 Answers

Yes you should learn Objective-C++ when you want to develop competitive comnerical strength (aka so good that people are willing to pay for them) Apple applications.

It is indeed nothing else the Objective-C and C++ combined in the same file.

For Objective-C use any of the hunderts of the popular apple development blogs/mailing lists/newsgroups. Especially the one directly provided by Apple.

For C++ this is the same, dozens of blogs/mailing lists/starter tutorials are there. But while C and its Objective-C add-on is pretty simple and easy to learn if you already understand programming. C++ is a total different and complex beast. Get a few good books and learn it (after 10 years you will be able to fully understand the language :-) but you can writing C++ programs with just a fraction of this knowledge.

So and now the magic question why you should use C++ when you could get away with Objective-C. The answer is pretty simple. Beside the obvious mentioned wrapping of existing C++ libraries, Objective-C is slow, first of all - method call. THe usual adivse is to do something serious in your methods to avoid this runtime penality that shows up in this language.

But especially for Containers you should really consider to use C++ templates. A vector is much much faster then an NSArray. If your dataset is large you will feel the difference. Also i find C++ containers easier to use because they avoid the typecasts you have to do with Objective-C.

With slow ARM CPU's on iPad and iPhone this is not premature optimization.

Unfortunately you can't mix C++ and Cocoa classes and therefore C++ should only be used for algorithmic data. For the GUI you have to use Cocoa and Objective-C classes.

Getting the right balance between C++ and Objective-C is some part of the skills you need to develop as a Apple programmer.

like image 177
Lothar Avatar answered Oct 17 '22 01:10

Lothar


Objective-C++ is really just mixing Objective-C with C++. Since it allows syntax from both you could argue that it is a new language.

I primarily use ObjC++ (.mm source files) when I have to interface Objective-C code with some C++ library. It is convenient to be able to call C++ in that case. Personally I do not know a lot of people who actually really mix C++ and Objective-C.

like image 38
Stefan Arentz Avatar answered Oct 17 '22 03:10

Stefan Arentz