|
|
Differences between C++ and Objective-C
|
|
|
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Buenos Aires, Argentina
Status:
Offline
|
|
Hi there
I'm learning C++ and I was wondering what are the main differences between C++ and Objective-C.
I know this could be really silly and easy question.
I'm learning C++ in the WinTel environment -and I hate Wintel!!. Is it possible to compile my code under OSX?? should I use gcc and Apple's developer tools?
Thanks again
N
|
iMac 1GHz 17" Super Drive
iPod 5GB
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
I'm learning C++ and I was wondering what are the main differences between C++ and Objective-C.
Well, uh... it might be easier to look at it the other way around. The similarity is that they're both based on C. The differences are everything else. The syntax for their extensions to C is completely different, the way object-oriented constructs work in each is completely different, and the thought and design patterns you have to follow to use each efficiently are completely different.
Is it possible to compile my code under OSX?? should I use gcc and Apple's developer tools?
Depends on what your C++ class is doing. If you're just writing little command-line tools based on standard libraries and templates, you should be able to use almost any development environment on almost any platform. See this article for some info on using Project Builder for this.
If you're using any special libraries or templates, or if you're writing GUI apps on Windows, you're pretty much out of luck in terms of being able to follow along on your Mac.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Buenos Aires, Argentina
Status:
Offline
|
|
Thanks for your prompt response!
What do you think about Objective-C vs C++?
Which one is better?
Thanks
N
|
iMac 1GHz 17" Super Drive
iPod 5GB
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Jun 2001
Location: Savoy, IL USA
Status:
Offline
|
|
Wow, this is a tough question. But, to answer one question that I think you're asking, but I'm not clear about is: "Can I do C++ programming in a Mac OS X environment" and the answer is, of course, yes. In fact, all the Mac OS X developer tools are based on the GNU compiler/debugger suite, and you can do 'old-skool' UNIX programming with Makefiles and all that BS if you want to...
To me, the differences between Obj-C and C++ are mostly superficial. Here are some of the more obvious differences:
1) The syntax for all the object orientation is completely different.
2) All Obj-C objects are heap-based (that is, are dynamically allocated) and use reference counting heavily to keep memory usage to a minimum. C++ objects can be either stack based (statically allocated) or heap-based. This is important because it means you have to pay a little more attention to memory management in Obj-C if you're used to using stack-based objects in C++.
3) The support libraries for each language (STL in the case of C++ and Cocoa in the case of Obj-C) are completely designed & implemented differently. Quality distinctions about these differences ("which is better?") really need to be made in the context of what you're trying to accomplish. One thing that I notice, though, is that Obj-C container classes perform rather poorly compared to C++ containers.
Everything else that I can think of just now is not really that big of a deal for me. I actually like Obj-C quite a lot, but more because I like Cocoa a whole lot. I love the STL and still love C++, but I seem to get a lot more done in Obj-C in shorter periods of time when designing/implementing code. Or, maybe the nature of my job has changed, and this is just an illusion...
Again, saying "what's better" is not something that one can answer for another person, I think. You need to educate yourself on the strengths and weeknesses of both to understand which should be used in what situations. I actually like a pragmatic mix of Obj-C and C++ (called, appropriately,"Objective C++") with a little Carbon thrown in when I can't avoid it. Cocoa still has some 'missing' functionality for things that you can only do in Carbon.
|
Software Architect, CodeTek Studios, Inc.
12" AlBook 867 (Combo drive) 640 MB/40 GB (work development machine) -- TiBook 400MHz/384MB/10GB (home machine)
CodeTek VirtualDesktop Pro: Power multitasking! -- DockExtender: Powerful, efficient launcher for Apps, Docs and everything else!
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
The basic similarity between the two languages is that they use a paradigm of "objects" from which you can "inherit" traits, and on which you can invoke "methods."
The basic difference is that in objective-C, you can do it at runtime without really knowing what sort of object is doing the sending or receiving. You can do this in C++, but it gets painful quickly.
C++ is a much lower-level language than objective-C. This means that it's faster, but that you have to work harder to accomplish things.
In any case, there's no "holy grail" language. If you want to develop a GUI quickly, objective-C roks. If performance is a factor, C++ or even C (or, I hate to say it, even Fortran) might be better.
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Buenos Aires, Argentina
Status:
Offline
|
|
Thanks a lot for the advice!
I guess I will stuck for C++ for a while and then move to Obj-C.
N
|
iMac 1GHz 17" Super Drive
iPod 5GB
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|