|
|
C++ or Objective-C?
|
|
|
|
Fresh-Faced Recruit
Join Date: Oct 2005
Status:
Offline
|
|
Hi, I'm new to software development so I was wondering, which programming language would be the best for Mac development, C++ or Objective-C. I will be programming in xCode, so which one will be the most expandable for my needs (I won't be programming games), will be the easiest to learn, and will be the most compatible. Thanks in advance.
(
Last edited by Spaceman Spiff; Jan 30, 2006 at 09:33 PM.
Reason: additional questioning)
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Oct 2005
Status:
Offline
|
|
Where should I go to learn (for the complete noob) about either one? After reading a few web pages, I kinda leaning towards Objective-C, but I can't find any that don't already require you to know C.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
In either case you should really learn plain C first. But for Mac-specific programing, Objective-C is the language of choice. It has the best integration with the Mac APIs (eg, Cocoa). It is also far simpler syntax-wise than C++.
For resources for learning, just do a search of this forum. The same question is asked and answered a zillion times a week... well almost.
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Oct 2005
Status:
Offline
|
|
Originally Posted by Brass
In either case you should really learn plain C first. But for Mac-specific programing, Objective-C is the language of choice. It has the best integration with the Mac APIs (eg, Cocoa). It is also far simpler syntax-wise than C++.
For resources for learning, just do a search of this forum. The same question is asked and answered a zillion times a week... well almost.
Ok, I'll start with C first, long road ahead I guess. Sorry about repeating a post...
Will Xcode compile plain C?
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status:
Offline
|
|
Yes, Xcode will compile ANSI compliant C code.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Xcode can compile C++, Objective-C and plain old C. So you've got a compiler no matter which you go with. And yeah, a search would probably turn up better recommendations than you'd get re-asking the question.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Oct 2004
Location: Downtown Austin, TX
Status:
Offline
|
|
Definitely spend most of your time learning C first. It helps to take a class in it. Then Objective-C will come easily.
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Sep 2003
Location: San Diego
Status:
Offline
|
|
Good luck making your decision. Like everyone, I agree that you should try and learn C first (or use the Cocoa bindings from a language like Python if learning C isn't your desire) Once you do that, learning C++ & Obj-C isn't that hard.
Just a few thoughts on language selection. If you're planning on developing for Macs only, then Obj-C would certainly be your best bet. However, if you want to use this experience to get a software engineering job, then your best bet would be to learn C++, as that is probably the most used language in computing. Either way, once you learn one, learning the other isn't too difficult.
I personally disagree with Brass' statement that Obj-C syntax is far simpler than C++. IMHO, C++ more closely follows the C language behaviors, while Obj-C has different syntax to call functions and methods to help out the compiler.
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Sep 2003
Location: San Diego
Status:
Offline
|
|
Originally Posted by PBG4 User
Yes, Xcode will compile ANSI compliant C code.
Wow! I thought that there was no way that XCode supported ANSI C, as I can't imagine anyone has written anything in ANSI C in at least 10 years! I'm quite impressed. My ANSI C syntax isn't quite up to par, so I didn't write a "Hello World" type function to see if it worked, though...
I would hope that most C programmers are using the C99 standard by now! It has support for naming variables anywhere in the function block (not just on the top of the function), and a few other nice changes.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Aug 2001
Status:
Offline
|
|
Originally Posted by smitty825
Wow! I thought that there was no way that XCode supported ANSI C, as I can't imagine anyone has written anything in ANSI C in at least 10 years! I'm quite impressed. My ANSI C syntax isn't quite up to par, so I didn't write a "Hello World" type function to see if it worked, though...
I would hope that most C programmers are using the C99 standard by now! It has support for naming variables anywhere in the function block (not just on the top of the function), and a few other nice changes.
You joke, but Xcode defaults to C89
Thankfully it's easy enough to change.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Originally Posted by smitty825
Wow! I thought that there was no way that XCode supported ANSI C, as I can't imagine anyone has written anything in ANSI C in at least 10 years!
You don't think anything has been written in C89 since 1995? What do you reckon all the C programmers were using in 1996?
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Originally Posted by smitty825
I personally disagree with Brass' statement that Obj-C syntax is far simpler than C++. IMHO, C++ more closely follows the C language behaviors, while Obj-C has different syntax to call functions and methods to help out the compiler.
1. Obj-C uses exactly the same syntax to call functions (but not methods, which don't exist in C at all). They are standard C, and Obj-C and C++ are merely alternative extensions of C.
2. For a complete description of the Obj-C extensions to C, see the documentation.
I think any description of the C++ extensions to C would be a lot longer (and a lot more difficult to understand) than this. However, that is subjective, and different people think in different ways, and what suits one person better may not suit another person better.
This link explains that Obj-C only has one syntactic extension to C (presumably they mean the use of square brackets for calling methods). Personally I'd say it has a couple of other extensions, such as method definitions. But the point is that there are very few additions to plain C.
This link explains that C++ is not even a true extension of C as it actually breaks some compatibility with C. I haven't looked into this, and the "brokenness" looks very trivial to me.
(
Last edited by Brass; Feb 1, 2006 at 07:00 PM.
)
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Objective-C has more than one syntactic extension to C. It adds keywords such as @implementation…@end and @try, and the <ProtocolName> syntax for indicating conformance to a protocol.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Oct 2005
Status:
Offline
|
|
Originally Posted by smitty825
Good luck making your decision. Like everyone, I agree that you should try and learn C first (or use the Cocoa bindings from a language like Python if learning C isn't your desire) Once you do that, learning C++ & Obj-C isn't that hard.
Just a few thoughts on language selection. If you're planning on developing for Macs only, then Obj-C would certainly be your best bet. However, if you want to use this experience to get a software engineering job, then your best bet would be to learn C++, as that is probably the most used language in computing. Either way, once you learn one, learning the other isn't too difficult.
I personally disagree with Brass' statement that Obj-C syntax is far simpler than C++. IMHO, C++ more closely follows the C language behaviors, while Obj-C has different syntax to call functions and methods to help out the compiler.
I will defiantly be writing Mac software 99.9% of the time, but if I want to write a Windows (or Linux) program, does a Obj-C compiler exist for Windows? I doubt I'll write a Windows program, but... will it be hard to write one if I settle into writing Objective-C code? This may be a stupid question, but can you write a full featured Mac app with C++, because under Xcode, C & C++ shows up as a command line application, not one with a GUI.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Originally Posted by Spaceman Spiff
I will defiantly be writing Mac software 99.9% of the time, but if I want to write a Windows (or Linux) program, does a Obj-C compiler exist for Windows? I doubt I'll write a Windows program, but... will it be hard to write one if I settle into writing Objective-C code?
Apparently you can, although I've never tried it, using GnuStep. It is an open implementation of the old NextStep (and now Apple's Cocoa) frameworks, including development tools.
This may be a stupid question, but can you write a full featured Mac app with C++, because under Xcode, C & C++ shows up as a command line application, not one with a GUI.
Yes, but I've never done it. I've only ever used Cocoa/Objective-C. I believe Carbon applications are usually done in C++, but others here could give you better information on that than I.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Originally Posted by Spaceman Spiff
I will defiantly be writing Mac software 99.9% of the time, but if I want to write a Windows (or Linux) program, does a Obj-C compiler exist for Windows? I doubt I'll write a Windows program, but... will it be hard to write one if I settle into writing Objective-C code?
They do, but it would likely be a lot more than a simple recompile —�but that's true of porting a C++ Mac program as well.
Originally Posted by Spaceman Spiff
This may be a stupid question, but can you write a full featured Mac app with C++, because under Xcode, C & C++ shows up as a command line application, not one with a GUI.
The only project type with "C++" in the name is a command-line tool, but that isn't the only one you can use C++ with. Most actual Mac apps written in C++ are Carbon applications, so that's the project type you'd use. Even an Objective-C Cocoa program can incorporate C++ code to a certain degree.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Sep 2003
Location: San Diego
Status:
Offline
|
|
Originally Posted by Chuckit
You don't think anything has been written in C89 since 1995? What do you reckon all the C programmers were using in 1996?
Whoops...I mistook ANSI C for the original K&R C! I had forgotten that ANSI C and C89 were essentially the same thing!
heh...good or K&R C... (yes, I had to look up the syntax)
Code:
int myFunc(x,y)
char* x, y;
{
...
}
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Oct 2005
Status:
Offline
|
|
Originally Posted by Chuckit
They do, but it would likely be a lot more than a simple recompile —�but that's true of porting a C++ Mac program as well.
The only project type with "C++" in the name is a command-line tool, but that isn't the only one you can use C++ with. Most actual Mac apps written in C++ are Carbon applications, so that's the project type you'd use. Even an Objective-C Cocoa program can incorporate C++ code to a certain degree.
So, if I used Carbon, would there be a difference (other than a checkbox or something?) I think that Carbon is/was for developers switching from OS 9 to OS X, so are some things impossible or harder done in Carbon than Cocoa?
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Carbon and Cocoa are very different. It's not that one is necessarily less capable than the other, they're just different. To generalize a lot, I would say Cocoa is "easier." Carbon is fairly massive and doesn't have as much of the friendly OO abstraction you get with Cocoa.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
I think that Apple originally inteded Carbon to be a "transition" technology from Classic Mac OS to Mac OS X. However, this is certainly not the case now. It is not the poor cousin to Cocoa, and I think it may even be faster than Cocoa in some some ways (Obj-C's ease-of-use implementation of OOP is not the speediest).
Having said that, I still prefer to use Cocoa/Obj-C.
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Aug 2002
Location: Atlanta, GA, USA
Status:
Offline
|
|
If you're writing new code, then cocoa is probably the best way to go since you're starting fresh. Carbon does have it's applications though and certainly could be used. IMO, carbon gives you a much "closer" feel to the operating system/hardware than cocoa does. There's a lot of abstraction in the cocoa frameworks. Most of the time, carbon applications are written in C++ but could also be in other languages as well. Carbon simply refers to the library you use and link to when you compile your app. Contrast that with using the cocoa frameworks which are all obj-c .
|
MBP C2D 2.16Ghz 15" Matte, 2GB RAM
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Cocoa is meant for Objective-C, but you can use other languages with it. Java, Perl, Python, Ruby and probably several others I haven't thought of all have Cocoa bridges.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Note that the Java bridge is deprecated, though.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
I thought the bridging technology was deprecated (Bridgette or whatever it was called), but Cocoa-Java was still alive. Did they deprecate the whole thing?
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Aug 2001
Status:
Offline
|
|
They've said that no future API will be added to Cocoa-Java, but existing ones will continue to work.
|
|
|
|
|
|
|
|
|
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
Definitely go with Cocoa/Objective-C. You can find plenty of information on how to do so in the archives.
C++ is a terrible language. Never learn it if you can help it.
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Oct 2005
Status:
Offline
|
|
Originally Posted by parallax
Definitely go with Cocoa/Objective-C. You can find plenty of information on how to do so in the archives.
C++ is a terrible language. Never learn it if you can help it.
I've started on C, and I plan to go onto Cocoa/Objective-C, but what makes C++ a terrible language?
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Feb 2006
Status:
Offline
|
|
Go to http://cocoadevcentral.com and read C tutorial. It gives you enough C to move on to ObjC. Whatever language you choose to learn, just remember that the languages aren't that difficult to learn, it's the APIs and framework that's really important.
BTW, C++ is not a terrible language. There should be only two languages in computing, C/C++ and SmallTalk. I also can't stand any language that tries to manage memory for you. I'm hoping for the day when the garbage collector disposes itself.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status:
Offline
|
|
Originally Posted by Spaceman Spiff
I've started on C, and I plan to go onto Cocoa/Objective-C, but what makes C++ a terrible language?
C++ is a strongly typed language, while Objective-C is a weakly typed language. Type errors get caught by the compiler with C++, but type errors get caught by paying users with Objective-C. This means that Objective-C is easier to program with, as you don't get as many compiler errors. With Objective-C, it's significantly easier to add common functions to unrelated objects. This can make it easier to program with. However, C++ makes sure you absolutely meant to do what you typed.
On the other hand, Cocoa is a far cleaner API than Carbon. Objective-C is heavily tied to Cocoa, while on the Mac, Carbon gets tied to C++ (though technically, it's a C interface). Since Cocoa is a much better API than Carbon, some people make the conclusion that C++ is terrible. (I'm not trying to say that anyone here is making this conclusion... that's just my two cents.)
|
ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
|
|
|
|
|
|
|
|
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
In short, C++ is a hack of an object-oriented system. There are places where it's just broken (search the web for details). Debugging errors with templates is a nightmare.
MacG33k, LISP is another language that should be in computing.
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
|
|
|
|
|
|
|
Senior User
Join Date: Feb 2000
Location: Burlington, VT, USA
Status:
Offline
|
|
Originally Posted by MacG33k
Go to http://cocoadevcentral.com and read C tutorial. It gives you enough C to move on to ObjC. Whatever language you choose to learn, just remember that the languages aren't that difficult to learn, it's the APIs and framework that's really important.
BTW, C++ is not a terrible language. There should be only two languages in computing, C/C++ and SmallTalk. I also can't stand any language that tries to manage memory for you. I'm hoping for the day when the garbage collector disposes itself.
I've gotta admit, this is one of the most ignorant posts I've ever read. Garbage collection is the greatest thing to be added to a programming language, ever.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|