View Full Version : C++ or Objective C
Feb 8, 2007, 10:00 PM
Ok quick question, I have been learning c++ by way of game programing through a book and have been progressing nicely. I have read online that objective c is the standard for cocoa and mac app writing. Also this is my first real programming language. I want to learn both but don't know which way would cause less headaches.
My question is should i jump ship to objective c and come back to c++ later or will it be better to learn, or at least get good, c++ and then go to objective c.
I'm sorry if this has been asked before but I have an awful time with the search function.
Feb 8, 2007, 10:58 PM
I was pretty much in the same boat as you. I originally learned C++ for game development. Then switched over C++ for Cocoa.
Personally, I think it would be good to learn both. C++ definitely will give you WAY more headaches. Objective-C is very flexible with it's dynamic runtime, and is true Object-Oriented language, while C++ is has a static runtime, and it kind of a mixed between OOP and procedural. I would learn Objective-C first because it isn't as tricky, and that it will give you a true OOP mindset, and moving from OOP to procedural (somewhat) is a lot easier in my opinion then vice versa. The syntax and felxibility of Objective-C might confuse you at first, but after that it's all smooth sailing :cool:
Feb 9, 2007, 12:11 AM
It's been asked a lot, actually, but if you want to create games on Mac OS X that could be compatible with other systems, you'll need to use C++.
Objective-C is a great language but it's pretty much limited to use on Mac OS X, though there are exceptions.
Within reason, you'll find many object-oriented languages close enough that you can move back and forth easily. You might be able to move code fairly easily, too, especially if you know the more complex features of the languages and carefully design around them.
Java also isn't that different than both C++ and Objective-C.
Since the syntax is very close, you could probably look at coding in Java at the same time as C++. When you get through classes and methods, try Objective-C through that same point.
Feb 9, 2007, 04:36 AM
I'd just like to add to the good advice that has been posted.
Sticking with C++ and STL is a good thing I think. It's not an all or nothing situation with regard to Cocoa and Objective-C. It's very easy to mix C++ and Objective-C in the same project. You can even mix C++ and objective-C in the same files. There are some restrictions though and Apple have a tech article about the limits of the Objective-C++ compiler. But it's actually very easy to use - in Xcode just use the extension .cpp for your files. If you are creating a Mac application you can use Objective-C and Cocoa to do all the interface stuff and C++ and STL for the 'guts' of the program.
There are similarities between Java and C++ but remember, don't use == to compare strings in Java as you would in C++, use .equals()!!! I program in both languages and every once in a while a == sneaks into my Java and causes me headaches tracking the problem down.
b e n
Feb 9, 2007, 04:56 AM
Im just a small apps developer, however i found coming from the languages like C++/PHP/PAWN and only knowing the moderate knowledge of them all, i found that ObjC was a big change in the way the code is written however after my first project i just fell in love with ObjC
Feb 9, 2007, 05:02 AM
The point is that ObjC and C++ both have their strengths and weaknesses. You must choose what is more suitable for you. I have made a post that will help you. And here it is:
No language can replace another. Objective C is not suitable for closed world applications. C++ is best for that. Objective C performs extremely well into open world applications.
Examples of closed and open world applications:
--Engine compartment of a car is closed world
--Passenger compartment of a car is open world.
(yes, this example is taken by Cocoa Programming book :))
For example. Working with NSSTrings is fabulous. But what this string type lacks, is functions for accessing individual characters inside an nsstring without calling a function. Operator overloading is missing (so, no <iostream>-like functions here) and you cannot ever,ever,ever make something like a stringstream. On the other hand, in C++, there is no ID object type (object whose type is determined at runtime). That little detail shows the things you can do with ObjC.
As you can see, there is no way one language can replace another. Your best bet is to use Objective C++ which marries elements from both worlds
My advice: Learn both. Each one will help you in different programming concepts. Of course C++ will guarantee programming into other platforms such as windows, but you should know that if you want to get involved with .NET or with Cocoa, you will want to know one additional language anyway, be it C#, or Objective-C, although C++ support on both systems is there.
So, why restrict yourself in learning C++ OR Obj-C? Learn both. Start with C++, as there are many references and will teach you about pointers etc (which will help you understand the Classes in Obj-C which are all created using pointers) and shalllow-deep copy. Then, learning Objective C will be a two-days mater for you. You can mix Objective C and C++ code in the same files, just by adding the ".mm" extension to your files. So, whatever your choice, the knowledge you will have acquired will not get wasted.
Many people here will tell you to go the other way around (learn Obj-C first) because ObjC is easier (and the C++ language is really huge), but I think that it would really help to understand the basic concepts of C++ first.
If you want to stick to C++, and not learn ObjC, you should know that there is also the Core Foundation framework, which (before my eyes, at least) is a substitute of the Foundation Framework of Objective C that provides the almost the same level of abstraction while maintaining compatibility with C and C++.
Feb 9, 2007, 05:20 AM
I can recommend Objective-C Pocket Reference by Andrew M. Duncan published by O'Reilly. It's small, fits in your pocket and got everything (probably) you need to know about Objective-C. It's very concise and you can get a pretty good understanding of Objective-C from reading it while walking your dog… assuming you have a dog.
b e n
Feb 9, 2007, 06:35 AM
I was always going to learn both, just which first would be better to learn first.
Im going to continue with c++ then move on to obj. c and on from their.
Thanks for all the help.