Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 1, 2013, 07:14 PM   #1
silentownage001
macrumors regular
 
Join Date: Dec 2011
Location: NJ
C, Obj-C, C++, some questions argh

After searching Google and this forum I have still not been able to fully find the answer.

As of now though I intend to write programs for iOS (I have some ideas) and later OS X if I think of anything.

Currently reading Objective-C Programming Big Nerd Ranch Guide. When I'm done I will hopefully have a good understanding of C and Objective-C after reading the advanced parts.

So far I'm still on Command Line Tools. I know you can select C++. I was wondering though that since you need Objective-C for Cocoa (from my understanding), what would C++ be used for? At least for iOS and OS X. I've seen someone say that it's a good compromise. Not entirely sure for what though.

Whatever language I learn next though, will most likely be dictated by what I want to program for next. I do wonder when I'll actually use C but understanding it will be quite helpful.
silentownage001 is offline   0 Reply With Quote
Old Feb 1, 2013, 08:14 PM   #2
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
C++ when used with restraint and some sense is a better programming language than C. If you use code written by others, especially if it is supposed to be portable between different operating systems, chances are it is written in C++.

In a MacOS X or iOS applications you can freely mix code written in C, Objective-C, C++ and Objective-C++.
gnasher729 is offline   0 Reply With Quote
Old Feb 1, 2013, 08:55 PM   #3
silentownage001
Thread Starter
macrumors regular
 
Join Date: Dec 2011
Location: NJ
That clears it up. Thanks. Since as of now I'll only be writing for iOS and OS X I think it'll be mostly written in Objective-C. Maybe some C, depending on what I need. Since I don't know C++ the other two are ruled out. Until I learn it at least.

Although, depending on the program, wouldn't C++ be better most of the time? Since it is object-oriented? I'm probably way off since there is probably more to it but I'll learn.
silentownage001 is offline   0 Reply With Quote
Old Feb 1, 2013, 10:45 PM   #4
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
Objective-C is also Object-Oriented. For now, that should suit you. C++ has its place, but I don't think you're in one of those places right now.

-Lee
lee1210 is offline   0 Reply With Quote
Old Feb 1, 2013, 10:49 PM   #5
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
Quote:
Originally Posted by silentownage001 View Post
That clears it up. Thanks. Since as of now I'll only be writing for iOS and OS X I think it'll be mostly written in Objective-C. Maybe some C, depending on what I need. Since I don't know C++ the other two are ruled out. Until I learn it at least.

Although, depending on the program, wouldn't C++ be better most of the time? Since it is object-oriented? I'm probably way off since there is probably more to it but I'll learn.
Object-oriented programming is not inherently better than procedural, though it's a useful tool for many tasks. C++ is also many things besides object-oriented. It's an enormous language, with many strong upsides and serious downsides.

Exploring many languages is a good way to expand your horizons, particularly ones that are very different from each other (procedural, functional, object-oriented, etc...). Takes a long time though.
Catfish_Man is offline   0 Reply With Quote
Old Feb 2, 2013, 07:43 AM   #6
silentownage001
Thread Starter
macrumors regular
 
Join Date: Dec 2011
Location: NJ
Ok. Thanks everyone
silentownage001 is offline   0 Reply With Quote
Old Feb 2, 2013, 10:16 AM   #7
ghellquist
macrumors regular
 
Join Date: Aug 2011
Location: Stockholm Sweden
My take on this.

The "best" language to use depends on what "problem" you are trying to solve.

If the "problem" is to write an application on IOS, the only language really useful is Objective-C. And you need to work with objects and learn some object oriented programming, as it is the basically the only way to do things on IOS.

Same language, Objetive-C, if mainpart of your program is about showing windows and menus and such stuff on Mac OS.

But on Windows, Objective-C is not a viable option. You need to write your program in a different language. Often C# or (ahem, clearing my throat here) Basic, as in Visual Basic .Net. Had to make a slight noise here as "real" programmers don't eat basic.

On some platforms, say an Android smart phone, the language of choice would probably be java.

If you do very large simulations or stuff like that, say forecasting the weather, you might use C or C++ but with additions allowing the program to be run concurrently on a a large number of computers (this is a special world in itsel).

But on a a web server neither languae is a good choice. There you would probably use something like PHP instead.

The real interesting stuff (at least I think so), happens when you want to share code base between different environments. This is definitely not a beginner subject. Then you migh want to write the logic stuff in C++, and have one graphic front-end for Mac written in Objective C, a different front end for Windows written in C#.

If you like really small computers, say for controlling a robot, C is probably the choice language.

So, to make it really short. If you like you mac and ios stuff, learn objective-C really good. Knowing one language really well will help you learning the next language. Knowing a lot of languages only on the surface might be interesting, but does not really get you into programming.

//Gunnar
ghellquist is offline   0 Reply With Quote
Old Feb 2, 2013, 11:33 AM   #8
silentownage001
Thread Starter
macrumors regular
 
Join Date: Dec 2011
Location: NJ
Thanks Gunnar. It's like learning speaking languages. Once you learn a second one it's easier to learn others.

Quote:
Originally Posted by ghellquist View Post
Same language, Objetive-C, if mainpart of your program is about showing windows and menus and such stuff on Mac OS.

//Gunnar
I'm not entirely sure what you mean by showing windows and menus. Depending on what you want to do on OS X would you sometimes use C or C++? I thought that Objective-C would pretty much be the only language, like iOS.
silentownage001 is offline   0 Reply With Quote
Old Feb 2, 2013, 12:45 PM   #9
xShane
macrumors 6502a
 
xShane's Avatar
 
Join Date: Nov 2012
Location: United States
Quote:
Originally Posted by silentownage001 View Post
Thanks Gunnar. It's like learning speaking languages. Once you learn a second one it's easier to learn others.



I'm not entirely sure what you mean by showing windows and menus. Depending on what you want to do on OS X would you sometimes use C or C++? I thought that Objective-C would pretty much be the only language, like iOS.
I think what he meant that is if your application (in theory) is just a basic user interface with windows and menus (the menu at the top), then Objective-C will fulfill your needs.
__________________
Macbook Pro 15" 2.6, 8GB, 750GB, 1GB VRAM
"Everything for the people, nothing by the people."

"Be the change that you wish to see in the world."
xShane is offline   0 Reply With Quote
Old Feb 2, 2013, 12:50 PM   #10
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by silentownage001 View Post
Depending on what you want to do on OS X would you sometimes use C or C++? I thought that Objective-C would pretty much be the only language, like iOS.
IOKit uses C++:
https://developer.apple.com/library/.../Features.html
See the heading "Language Choice".

Since Objective-C is a superset of C, any valid C program is also a valid Objective-C program. Many, if not most, command-line tools are written entirely in C. One reason for this is they're portable, often from (or to) other Posix-like platforms that have C and C++, but not Objective-C. Hence, the portable language options do not include Objective-C.
chown33 is offline   0 Reply With Quote
Old Feb 2, 2013, 04:01 PM   #11
silentownage001
Thread Starter
macrumors regular
 
Join Date: Dec 2011
Location: NJ
Thanks. So depending on what I'm trying to do in OS X, I could use Objective-C or C++?

Also, would that mean that C programs would work in C++?
silentownage001 is offline   0 Reply With Quote
Old Feb 2, 2013, 05:17 PM   #12
ghellquist
macrumors regular
 
Join Date: Aug 2011
Location: Stockholm Sweden
Quote:
Originally Posted by silentownage001 View Post
Thanks Gunnar. It's like learning speaking languages. Once you learn a second one it's easier to learn others.

I'm not entirely sure what you mean by showing windows and menus. Depending on what you want to do on OS X would you sometimes use C or C++? I thought that Objective-C would pretty much be the only language, like iOS.
There are other types of programs

I have several programs that reads a text file, does some manipulation on that, and creates a new textfile. None of these programs has any menus, windows or selection boxes. These programs are not written i Objective-C. Some are written in Pearl, some directly as commands, some are in yet other languages.

I also dabble a bit in web pages. These are mostly written in PHP and using an SQL database. And SQL is actually one more computer language.

// Gunnar
ghellquist is offline   0 Reply With Quote
Old Feb 2, 2013, 05:43 PM   #13
silentownage001
Thread Starter
macrumors regular
 
Join Date: Dec 2011
Location: NJ
Ok, so sometimes a program won't be written in xcode?
silentownage001 is offline   0 Reply With Quote
Old Feb 2, 2013, 06:35 PM   #14
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by silentownage001 View Post
Thanks. So depending on what I'm trying to do in OS X, I could use Objective-C or C++?

Also, would that mean that C programs would work in C++?
C++ is quite close to being a superset of C, but not identical. Many C programs can be compiled by a C++ compiler and will work, but not all. Objective-C is a superset of C; all C code is valid Objective-C code. Obviously it is Objective-C code that doesn't use many Objective-C features.
gnasher729 is offline   0 Reply With Quote
Old Feb 2, 2013, 07:30 PM   #15
silentownage001
Thread Starter
macrumors regular
 
Join Date: Dec 2011
Location: NJ
Quote:
Originally Posted by gnasher729 View Post
Obviously it is Objective-C code that doesn't use many Objective-C features.
Did you mean C++ or something? That doesn't seem to make sense.
silentownage001 is offline   0 Reply With Quote
Old Feb 3, 2013, 11:35 AM   #16
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by silentownage001 View Post
Did you mean C++ or something? That doesn't seem to make sense.
Try adding the immediately preceeding half sentence.
gnasher729 is offline   0 Reply With Quote
Old Feb 3, 2013, 12:05 PM   #17
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by silentownage001 View Post
Ok, so sometimes a program won't be written in xcode?
I do believe you're having much, much too much thrown at you at once right now.

Xcode allows you to manage putting together complicated programs. When you're first learning how to program, I would advise against using it because it does too many things automagically.

I suggest using a text editor, like gedit, coupled with the Terminal command "clang" to program if you're just getting started. If you're not using any UI elements yet, there's no need to be using Xcode.
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote
Old Feb 3, 2013, 01:03 PM   #18
silentownage001
Thread Starter
macrumors regular
 
Join Date: Dec 2011
Location: NJ
Quote:
Originally Posted by gnasher729 View Post
Try adding the immediately preceeding half sentence.
So Objective-C doesn't use many Objective-C features?

Quote:
Originally Posted by ArtOfWarfare View Post
I do believe you're having much, much too much thrown at you at once right now.

Xcode allows you to manage putting together complicated programs. When you're first learning how to program, I would advise against using it because it does too many things automagically.

I suggest using a text editor, like gedit, coupled with the Terminal command "clang" to program if you're just getting started. If you're not using any UI elements yet, there's no need to be using Xcode.
I'll look into that. Thanks.
silentownage001 is offline   0 Reply With Quote
Old Feb 3, 2013, 02:37 PM   #19
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by silentownage001 View Post
So Objective-C doesn't use many Objective-C features?
"all C code is valid Objective-C code. Obviously it is Objective-C code that doesn't use many Objective-C features."
gnasher729 is offline   0 Reply With Quote
Old Feb 3, 2013, 02:58 PM   #20
silentownage001
Thread Starter
macrumors regular
 
Join Date: Dec 2011
Location: NJ
Quote:
Originally Posted by gnasher729 View Post
"all C code is valid Objective-C code. Obviously it is Objective-C code that doesn't use many Objective-C features."
Yea, I get the first part, all C code is valid Objective-C code. But how could Objective-C code not use many Objective-C features.
silentownage001 is offline   0 Reply With Quote
Old Feb 3, 2013, 03:20 PM   #21
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
=[ English is ambiguous.
"all C code is valid Objective-C code. Obviously it(it being C code) is Objective-C code that doesn't use many Objective-C features."

This is saying that you can write C, compile it as Objective-C, and it will work. You can refer to any C code as Objective-C, and you're right. But that C code doesn't use any Objective-C features because while it is valid Objective-C, if it's C by definition it does not use Objective-C features.

This conversation has devolved to a point that it is no longer useful to the OP. All three languages can be used for lots of things. You can use them all to write iOS and OS X apps. Some libraries and frameworks only have one API for one language, so you at least need to use that language to use the library. Maybe you just use that language to write a shim/adapter for another.

Stop trying to think through all this stuff. Write code in the language you're learning. When you need another language or want to learn it, deal with it then.

-Lee
lee1210 is offline   0 Reply With Quote
Old Feb 3, 2013, 03:25 PM   #22
silentownage001
Thread Starter
macrumors regular
 
Join Date: Dec 2011
Location: NJ
Quote:
Originally Posted by lee1210 View Post
This is saying that you can write C, compile it as Objective-C, and it will work. You can refer to any C code as Objective-C, and you're right. But that C code doesn't use any Objective-C features because while it is valid Objective-C, if it's C by definition it does not use Objective-C features.
-Lee
That makes sense, thanks.
silentownage001 is offline   0 Reply With Quote
Old Feb 3, 2013, 04:23 PM   #23
ghellquist
macrumors regular
 
Join Date: Aug 2011
Location: Stockholm Sweden
Quote:
Originally Posted by silentownage001 View Post
After searching Google and this forum I have still not been able to fully find the answer.

As of now though I intend to write programs for iOS (I have some ideas) and later OS X if I think of anything.
Original question, original answer: learn objective-C. Write code for IOS and Mac OSX. It will be object oriented.

When writing Objective-C code for IOS especially, and mostly when writing for Mac OSX, do use Xcode. Yes, xcode does a lot of magic, but it is exactly the kind of magic you need to get the code running on IOS.

If you learn objective-C well you will learn a lot of useful things. Most of these will travel with you to other languages and other environments, some will not. One of the things that will travel is the object oriented concept of MVC, which is more or less compulsory on IOS. You will find something similar in all GUI type frameworks regardless of programming language.

Once you have written your first few IOS programs (not book or class assignments) and your first few Mac OSX programs, you might want to look into other languages. That day is not now.

// Gunnar
ghellquist is offline   0 Reply With Quote
Old Feb 3, 2013, 04:32 PM   #24
silentownage001
Thread Starter
macrumors regular
 
Join Date: Dec 2011
Location: NJ
Thanks Gunnar.
silentownage001 is offline   0 Reply With Quote
Old Feb 12, 2013, 01:20 AM   #25
firewood
macrumors 603
 
Join Date: Jul 2003
Location: Silicon Valley
Quote:
Originally Posted by silentownage001 View Post
So Objective-C doesn't use many Objective-C features? ....
Yes. Objective C is a big enough language that, yes, it is possible to write big programs in it that use very few of the whole language's features. The Turing-complete subsets can be quite small. Not all of a big language's features are useful or required for all problems.
firewood is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Learning Obj-c feedback arkmannj iPhone/iPad Programming 11 Apr 24, 2014 11:22 PM
What to learn aside Obj C Will0827 iPhone/iPad Programming 8 Sep 27, 2012 03:07 PM
Argh IR and options Engali MacBook Pro 1 Sep 22, 2012 01:13 PM
ARgh - 4s or wait sdmfer iPhone 19 Jul 11, 2012 12:53 PM
Need help with indexing (Java or Obj-C) iVikD Mac Programming 5 Jul 5, 2012 05:43 PM

Forum Jump

All times are GMT -5. The time now is 12:11 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC