Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Josh Kahane

macrumors 6502
Original poster
Aug 29, 2006
439
1
Suffolk, UK
Hi

I previously asked on another forum on where to start if i wanted to program for the iPhone/iPod Touch. They said start with OSX. Im only 15 want to start early learn stuff over my summer holidays, where should i start? I dont know a thing by the way yet. Im am at the very beginning. Any help much appreciated, thanks.
 

Farani

macrumors 6502
Oct 21, 2007
267
0
Hi

I previously asked on another forum on where to start if i wanted to program for the iPhone/iPod Touch. They said start with OSX. Im only 15 want to start early learn stuff over my summer holidays, where should i start? I dont know a thing by the way yet. Im am at the very beginning. Any help much appreciated, thanks.

Well when I was 13 I started off teaching myself Visual Basic 5 for windows making old school progs for aol 3.0 lol.

But I'm kinda in the same spot as you. I'm a computer programming student. I just bought my first mac about a year ago. I'm learning this summer how to program for the mac. I won't be learning this in school so I have to do it on my own.

Anywho, I have a strong C++ background, which can be an advantage and a curse. If you want to learn some basic programming principles, a good language to start is BASIC. It won't get you programming for the iPhone, but I thought I'd throw it out there.

If you wanna jump right in, you wanna learn Cocoa and Objective-C. Apple brought out Objective-C 2.0 with OS 10.5 which includes a garbage collector and dot syntax, but I have been unable to find a good book out yet covering it.

I want to program for the iPhone also, so my plan of attack is to learn Objective C and Cocoa and then once I know those I can pour through the Apple docs and figure out the differences and nuances in Cocoa Touch. After researching it, these books are your best bet as of now:

Cocoa Programming for Max OS X THIRD EDITION by Aaron Hillegass
Programming in Objective-C by Stephen Kochan

Programming in Obj-C 2.0 is coming out in Nov. Make sure you get the third edition of the cocoa book; it will cover the garbage collector and the new stuff in XCODE 3.

There is also an iPhone Developers cookbook by Erica Sadun comming in Oct. This will show you how to use the SDK to program for the iphone.

Hope that helps. I'm sure I mentioned some stuff that doesn't make sense yet, but get those books and you will. Just take your time.
 

ChrisA

macrumors G5
Jan 5, 2006
12,576
1,692
Redondo Beach, California
Hi

I previously asked on another forum on where to start if i wanted to program for the iPhone/iPod Touch. They said start with OSX. Im only 15 want to start early learn stuff over my summer holidays, where should i start? I dont know a thing by the way yet. Im am at the very beginning. Any help much appreciated, thanks.

The place to start is with C, C++ or Objective C programing. At first you will create programs that run at the command line. These will accept typed input and create printed output. You may as well start with "plain old ANSI C" as that is the foundation for everything else. You are going to need a book length introduction. So you next question for the forum is "What is a good intro level book for C programming?" Don't worry about Cocca programming on Macs. At this point you just need to know programming in plain on C on the command line.

OK, you are starting from dead zero. The first thing you want to do is to get the "Hello World" program to run.

Code:
int main()
{
  printf("Hello World\n");
}

Put the above inside a file called hello.c and then compile it with "gcc -o hello hello.c" and run it by typing "./hello".

After that you change the program to do something more useful, like find the first 100 prime numbers or whatever. Then write something to accept some typed words and alphabetize them. Much later you can worry about xcode and building a graphic interface then later you can do the same on an iPhone. But the Mac is a much nicer place to learn than the iPhone and everything you learn will carry over.
 

Farani

macrumors 6502
Oct 21, 2007
267
0
There's no return value in your main code you gave him.

Oh snap! That's a compiler warning if I've ever seen one!


Yeah that biggest thing about programming is the logic. If you can understand the logic, the language isn't a big deal. The one thing I've noticed thus far going from C++ to Obj-C is how much more object-oriented it is. Make sure you have a good understanding of pointers and you'll understand objects better.
 

Farani

macrumors 6502
Oct 21, 2007
267
0
So you next question for the forum is "What is a good intro level book for C programming?"

Programming in Objective-C is a good book, but it can be unclear on a lot of things. I think if I didn't already know C++, I would have had more trouble with this book. I don't know any C books, but I can recommend a good C++ book if you're interested...
 

Farani

macrumors 6502
Oct 21, 2007
267
0
Hmm, ignore me. I must have had a brain fart.

Compiles fine *grumbles under breath*.

lol I refuse to ignore you, sir!

No, I was honestly asking, not implying you were wrong in any way. To be honest, I have programmed almost nothing in XCode. I've merely been reading Obj-C and Cocoa books. I don't need the basic command line programs that books teach (I've done all of that in C++), so I'm just starting to get into the Interface Builder material. So I really was asking if it would compile or not.
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
lol I refuse to ignore you, sir!

No, I was honestly asking, not implying you were wrong in any way. To be honest, I have programmed almost nothing in XCode. I've merely been reading Obj-C and Cocoa books. I don't need the basic command line programs that books teach (I've done all of that in C++), so I'm just starting to get into the Interface Builder material. So I really was asking if it would compile or not.

Basically (and this what I got confused about) in C99 you are not allowed implicit return types. That is why the following is not allowed:

Code:
main()
{
     // blah
}

this is fine though as it explicitly states the return value although personally I would add void to the arguments list.

Code:
int main()
{
    // blah
}
 

skateme

macrumors newbie
Jul 14, 2008
3
0
An easy (and powerful) language to learn is AppleScript. The syntax is read like plain English and you can create some pretty good apps with it. Pretty sure it won't work on iPhone but it's a pretty good start for Mac dev.
 

Denarius

macrumors 6502a
Feb 5, 2008
690
0
Gironde, France
An easy (and powerful) language to learn is AppleScript. The syntax is read like plain English and you can create some pretty good apps with it. Pretty sure it won't work on iPhone but it's a pretty good start for Mac dev.


There's also Perl and Python, which are pre-installed on a mac (have never really used them so can't comment on them). For my money though, Ruby (which I do use) is a good starting point as the syntax is beautifully intuitive, it's 100% object-oriented, making it a great launch-pad for objective-C and there's a little beauty called appscript Ruby that enables you to use it as an alternative to AppleScript if you're so inclined.

Definitely agree that you'd do well to kick off with a scripting language though as you'll be able to practise your hand at programming logic and structuring classes without being overwhelmed with memory management and other things straight off.

I'd hesitate at saying go for objective-c straight off. I started learning Cocoa programming with Objective-C about a week ago having been programming PHP for about 2 years and Ruby for about 6 months and while I think I'm doing alright, I suspect if I'd picked it up 2 years ago I'd have thrown it out of the window by about chapter 6. :)
 

Farani

macrumors 6502
Oct 21, 2007
267
0
Basically (and this what I got confused about) in C99 you are not allowed implicit return types. That is why the following is not allowed:

Code:
main()
{
     // blah
}

this is fine though as it explicitly states the return value although personally I would add void to the arguments list.

Code:
int main()
{
    // blah
}

ahhh ok gotcha. What is C99? Is it just a different standard of C?
 

Denarius

macrumors 6502a
Feb 5, 2008
690
0
Gironde, France
Code:
int main()
{
    // blah
}
[/QUOTE]

Sorry to digress, but how can this main function return an integer if the function inside isn't actually doing anything to return a value? Or is it just implicitly returning 0 for successful completion?
 

Farani

macrumors 6502
Oct 21, 2007
267
0
I'd hesitate at saying go for objective-c straight off. I started learning Cocoa programming with Objective-C about a week ago having been programming PHP for about 2 years and Ruby for about 6 months and while I think I'm doing alright, I suspect if I'd picked it up 2 years ago I'd have thrown it out of the window by about chapter 6. :)

I can't comment on Ruby, but C++ really isn't a bad starting point for Objective C, either. Objective-C gets into Objects right away. My biggest gripe with the book I've recommended is that it introduces pointers at the end, and basically tells you to skip them. The author believes it will hurt your understanding. I believe they will help you with objects. A book like "Starting Out With C++" by Tony Gaddis doesn't get into object oriented programming until about half way into the book, so you get a good understanding of loops, functions (methods in Obj-C), arrays, pointers, etc. Then he shows you classes. I feel like this really has made Obj-C easy for me to learn. I had to adjust/shift my idea of objects a bit, because Obj-C uses them slightly differently, but when the author was doing things with pointers in the Obj-C book and explaining nothing about them, I knew exactly what was going on.

Bottom line: Learn how to do command line programming first. When you have a good foundation there, you're ready to step into a graphical interface.
 

Farani

macrumors 6502
Oct 21, 2007
267
0
Sorry to digress, but how can this main function return an integer if the function inside isn't actually doing anything to return a value? Or is it just implicitly returning 0 for successful completion?

You need to "return 0" at the end of this for it to be proper; it isn't implicitly doing anything. This is why you'll get a warning doing it. You return 0 back to the OS at the competition of the program to indicate that the program has executed successfully.
 

MrFusion

macrumors 6502a
Jun 8, 2005
613
0
West-Europe
Anywho, I have a strong C++ background, which can be an advantage and a curse. If you want to learn some basic programming principles, a good language to start is BASIC. It won't get you programming for the iPhone, but I thought I'd throw it out there.
.
I don't know BASIC, never used. But I have read many times that BASIC is a terrible language and that people who learning programming with that language are basically beyond all redemption as programmers.
I don't know what the rational is behind it, but maybe it's better to be safe than sorry and thus stay away from BASIC. No insults intended here.

A better place to start would be scripting languages such as php or perl, then move on to command line based programming with c or obj-c, before moving on the full fledge GUI based programmes.
 

Farani

macrumors 6502
Oct 21, 2007
267
0
I don't know BASIC, never used. But I have read many times that BASIC is a terrible language and that people who learning programming with that language are basically beyond all redemption as programmers.
I don't know what the rational is behind it, but maybe it's better to be safe than sorry and thus stay away from BASIC. No insults intended here.

A better place to start would be scripting languages such as php or perl, then move on to command line based programming with c or obj-c, before moving on the full fledge GUI based programmes.

lol no insult taken. What exactly do you mean beyond all redemption? BASIC is an old language. It is just as the title says, basic. Definitely not object-oriented. But it will get you working with loops, functions, etc, doing command line things. I took it in high school before C++. It was True Basic. A lot of people took it as an easy elective. I would recommend C++ based off my experience... I'm not saying other people's suggestions are worse or better. They might be much better. I'm just saying from the experience I have and how it has worked for me.
 

Josh Kahane

macrumors 6502
Original poster
Aug 29, 2006
439
1
Suffolk, UK
This is great guys, thanks, ill look into guides on AppleScript and Objective C/Cocoa. Although whats the link between Objective C and Cocoa? Also which would be easier to learn (as i dont know a thing yet), Apple Script or C? One more thing, whats the best way to learn, doing exercises, or reading the manual and sort of working through? Thanks.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
This is great guys, thanks, ill look into guides on AppleScript and Objective C/Cocoa. Although whats the link between Objective C and Cocoa? Also which would be easier to learn (as i dont know a thing yet), Apple Script or C? One more thing, whats the best way to learn, doing exercises, or reading the manual and sort of working through? Thanks.

Sorry one more thing. Whats the difference between Objective C and C++?

Objective-C is a language. Cocoa is an Application Programming Interface (API). Cocoa gives you access to the OS X internals through a defined set of actions. Cocoa is an Objective-C API, so that is the preferred language for accessing it. There are bridges to other languages like Python, but the most direct means of access is by programming in Objective-C.

AppleScript might be easier to start with than C, but C will take you further towards the goal of being a proficient programmer.

I believe that there is no better way to learn than to do. Exercises are the way to go. Reading and knowing how to read/understand documentation is very important, but if you read a cook book from start to finish, you would not be a master chef. You have to apply what you are reading immediately, in my opinion, for it to stick.

C++ is a programming language with a long heritage. It is about 25 years old. It is not a proper superset of C, but uses a lot of C syntax while adding Object-Oriented programming as a supported programming paradigm. Object-Oriented programming is a means to group like functionality and data into packets called Objects. C++ is used for things like OpenGL graphics programming, Win32 programming, and a number of other tasks. I will leave the subjective discussion of its merits relative to Objective-C alone.

Objective-C is also a programming language with a long heritage, but it has only recently begun to gain momentum. It was the lingua franca of the NeXTStep platform, and when NeXT was acquired by Apple it became the lingua franca of the OS X platform. It is a proper superset of C, adding syntax to support Objects. One major difference between Objective-C and C++ is the type binding. This is not going to mean a lot to you now, but this is important to Cocoa once you get there. Another major difference is the way methods are called on Objects. In C++ method invocations must be resolved at compile-time, even if they can be overridden at runtime. Invocations in Objective-C are performed using a message-passing protocol inherited from SmallTalk. This means that a message pass can fail at run time, but also allows for more run-time flexibility.

All of this is, likely, gibberish to you. Really what you need to know is that C++ and Objective-C are both C-style languages that add syntax to support Object-Oriented programming. If you want to program native applications in the future on OS X, Objective-C is the best candidate. If you want to program against an API that is C++ based, that is a better choice. You can write against an API called Carbon on OS X with C++, but it was built as a bridge for developers moving from Windows and Classic Mac OS to OS X. It is quickly losing favor as Apple is not updating it to include features as OS X matures.

Hopefully this is helpful, if somewhat overwrought.

-Lee
 

MrFusion

macrumors 6502a
Jun 8, 2005
613
0
West-Europe
lol no insult taken. What exactly do you mean beyond all redemption? BASIC is an old language. It is just as the title says, basic. Definitely not object-oriented. But it will get you working with loops, functions, etc, doing command line things. I took it in high school before C++. It was True Basic. A lot of people took it as an easy elective. I would recommend C++ based off my experience... I'm not saying other people's suggestions are worse or better. They might be much better. I'm just saying from the experience I have and how it has worked for me.

"It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration." Dijkstra.

I am not a CS-guy, but from what I gather Dijkstra is an important computer scientist, and many people apparently share his view or parrot it (like me). I only mention this because the person asking the question is new to the world of programming and might not be aware of this view on Basic. Every language has it opponents and champions, but the opinions about Basic in this regard seem to be tilted quite strongly against the language.
 

Denarius

macrumors 6502a
Feb 5, 2008
690
0
Gironde, France
You need to "return 0" at the end of this for it to be proper; it isn't implicitly doing anything. This is why you'll get a warning doing it. You return 0 back to the OS at the competition of the program to indicate that the program has executed successfully.

Oh good, so it doesn't really work. That's reassuring. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.