The following is from Apple’s developer forums - two questions regarding Development for Beginners?

  • I'm completely new to computer programming. I've done a bit of web development (mainly HTML and CSS, some JavaScript, I'm working on PHP), but nothing on desktop systems. Apple's documentation is really technical and assumes that you already know Objective-C. Can someone recommend good online or print resources that teach Objective-C and Cocoa as related to iPhone (preferably) or OS X programming from the very basics?


  • Anyway, the thing is, I've looked up several posts on this and everyone says learn C or C++ first. I've never programmed anything at all before, and so I don't understand why its necessary. Learning 2 or 3 languages (or 4, as some people suggested I learn Java) will take me much more time and effort than simply learning one, I think. Or is objective-C (Cocoa) is so difficult that I must learn one of the other languages first?


Answers:


You need to learn C first.



It's hard to say where you should start without knowing more about your background and aptitude. If you have the opportunity, the best possible choice would be a local community college course in programming. See if you can find a first course in the "C" language (preferable without C++). The advantages of a live course can't be over estimated. But if that's impossible, the next best place to go is a good bookstore. Browse books by opening them to Chapter 2 or 3 and see if those pages are easy to read and if you learn something useful on the spot.

Look for books with titles like "Learn Programming Using C". That will be a book that assumes you've never programmed and introduces the C language for the purpose of teaching programming.

All of the above is the foundation for starting to actually program in Obj-C with Cocoa. When you're ready for that step you want either Cocoa Programming for Mac OS X (3rd Edition) by Aaron Hillegass or Beginning iPhone Development: Exploring the iPhone SDK by Mark and LaMarche or both. Either book will take you from a beginner skill level in C, to Obj-C, Mac development tools and then to building Cocoa apps with the OS X or iPhone SDK.

You might already be prepared for either Hillegass or Mark & LaMarche: I just can't say. But if you're going to be a real programmer, please try to take a college course or two. There's no better way to start.

Moving from what will help to what will not: Do not (as in please don't ever!) attempt to scrounge a basic understanding of programming from online blogs, forums, etc. In fact for the first few months, the less time you spend on the web, the better. By the time you're half way through Mark & LaMarche, you'll suddenly discover you can understand more than half of the iPhone Dev Center library. That's when you can go back online.

And when you get to the point of writing your own code, and after 2 sleepless nights in a row you can't see why it doesn't work, then come back to this forum, post your code, and we'll all fight each other to be the first to help you (because of course, it will be obvious you've done your homework and thus probably found out where to click when you get good help!).

Hope that gets you started!



Because both C++ and Objective-C came from C. If you learn C++ you will have to un-learn some stuff to do objective-C. (While most programmers are comfortable using several languages, that is not a good goal at the beginning.) Objective-C (as well as C++) adds the object oriented stuff on top of plain C. So once you learn C, you can graduate to objective-c in order to pick up object-oriented programming.



You still need to learn C before C++ will make any sense.



Hi, and welcome to the Dev Forums! Your question is asked often, yes, but it's never a bother. Most of the developers here are very happy to have the opportunity to help someone get started. Also, your question can't be answered properly in a FAQ because the path you need to take depends on your interests, objectives, aptitude and background.

C yes, C++ no. I agree completely with Bang on that. To clarify that point, Obj-C is a "superset" of C, meaning that it includes all of C and adds "object oriented" (OO) structure, including some very powerful and fun features. Therefore everything you learn about C will apply 100% to Obj-C, and I promise you'll never regret getting proficient in C before you get into Obj-C.

C++ is also a superset of C, and is also an OO language. It's just a different branch of the same tree. However, very little of the time you spend with C++ will help you with Obj-C. In fact I think Obj-C is a little easier to learn if you haven't yet learned to think in terms of C++.

The C Programming Language is the original explanation of the language, co-authored by the creator of C. There's nothing like going to original sources when you want to learn something, and I found that book to be very clear and easy to follow. But you're the only one who can say which book is best for you. At a time in your life when $40 is a lot of money, you need to select your books carefully.

I would recommend a trip to a good bookstore to spend several hours or a day or two browsing the C programming section (if the store doesn't have at least 2 shelves filled with books on C. it's the wrong store). Travel to the big city if you don't live there and visit a good store. There's no law that says you need $40 in your pocket on your first trip. Once you know exactly which book you want, you may find your local library will special order it for you. Or you may find a used copy of the book somewhere.

Look for books with names like "Learn programming using C". In other words you want a book that is primarily about how to program a computer and only secondarily about the particular language you're going to use in the process. When you find such a book, sit down with it and see if you like the way it explains things.

Is there a computer club or any other support for a new programmer at your school? Look around. The guy with poor eyesight, dirty hair and no social skills in your algebra class might be writing the next Linux. A friend you can study with can make a big difference.

Re Hillegass, I respectfully disagree with Bang. The book won't make you a professional programmer but it will make Obj-C and Cocoa easy for you, especially if you already know some C (and the more the better as mentioned above). However you might be better off putting your limited resources into learning fundamental programming concepts right now. Hillegass can probably wait awhile. I'd only advise you to start Cocoa asap if you need to start opening windows and drawing pictures on your Mac right away. I hope you have enough focus and interest in programming concepts to be happy with plain text for now.

While learning C, you won't be making Graphical User Interface (GUI) applications. Learning C is about learning what a variable is, the difference between an integer and a float, how to put characters into an array without crashing your program, and how to make a program that reads 2 and 3, then prints 5 or 6. This is time well spent. And once you learn how C pointers work, and how to make data structures with them, you'll be light years ahead of someone who decides to learn programming by making GUI apps with power tools.



Since we're on a roll, please bear with me for one more piece of advice. No matter how clear and well written, a book like K&R isn't intended to be read like a novel. Just like a math or physics text, you must do all the problems and code all the tutorials step by step as you study the book.

Previously we didn't discuss your programming environment, but I assume you have a Mac and may or may not have the Mac development tools. If you don't yet have a Mac, btw, you can setup a good C environment on any flavor of computer.

If you have a Mac, and have installed the dev environment from a CD, or downloaded it from either the iPhone or Mac Dev Center, you can compile and test C programs either with or without the Xcode application.

If you wish, you can access the C compiler directly by opening your Terminal application. In that case you would enter your code into a text editor and save it as a ".c" file (e.g. HelloWorld.c). When ready to test, you would type 'gcc HelloWorld.c'. After correcting any compiler warnings printed under your gcc command, you would repeat the command, and eventually the compiler would build an "executable" file named a.out. By typing './a.out' you would run your program and observe the output and/or error messages in the same Terminal window.

However, this "command line" interface can be difficult to use at first. There are lots of other commands you'll want to learn (e.g. 'man', 'ls -lt'). If you don't know anyone who's ever programmed that way, guidance might be hard to find. Most of the books that teach how to use a compiler will assume you have a GUI Integrated Dev Environment (IDE) such as Xcode. The exception might be a beginning C programming book for Unix. In that case the book might describe the very same environment you have with your Terminal app. In fact, when K&R was written, and for the next 15 years after that, most students were probably doing the problems and tutorials on a Unix sysytem, therefore seeing exactly what you would see in your Terminal screen. You may see references or assumptions about that text environment in K&R or other classic books, which is one reason I'm describing it.

The easier, if less instructive, programming environment on your Mac is Xcode. There are instructions in the first couple chapters of Hillegass on how to use Xcode. However I think those are aimed at your first Cocoa project instead of a beginning C program. The good news is that there are dozens of tutorials on using Xcode, so unlike the old-fashioned command line interface, info should be plentiful (e.g. see the Xcode Project Management Guide). Here are the steps to start a simple C project in Xcode:
1) Start Xcode (it's in /Developer/Applications btw, so drag the icon into your Dock);
2) Select File->New Project from the top menu;
3) In the New Project window, under Mac OS X in the left panel, select Command Line Utility;
4) Select the Standard Tool icon from center-right panel and click Choose...
5) In the next window, Save As: Hello, select a folder (e.g. Desktop), and click Save;
6) A window titled Hello should now appear; this is your Xcode project window;
7) On the left side you should see a tree panel titled Groups & Files;
8) Expand the Source folder under Hello and select main.c;
9) The contents of main.c should now appear in the lower-center-right panel;
+ You can both view and edit the file in that panel;
+ You can open a separate editing window by double clicking on main.c in the tree panel;
+ Don't edit the file right now;
10) Open up K&R, find the "Hello World" example program and compare it with main.c;
11) Select Run->Console from the Xcode menu to bring up the Debugger Console window;
12) Click on the Build & Go icon in the top toolbar of the Console;

You should see something like this in the Console:
[Session started at 2009-07-19 19:47:00 -0700.]
Hello, World!
The Debugger has exited with status 0.
K&R will discuss the printf() function which produced the "Hello, World!" output. When testing your project in Xcode, the output from printf() will always appear in your Console. So always open the Console before you start testing (it can be set to always open in Xcode->Preferences->Debugging).





All my programs are written in REALbasic - if you’d like to know more about REALbasic then just go to the REALsoftware website.





REALbasic affiliate program:

If after trying REALbasic you decided to buy it then you can support this site and the software I develop by clicking the image left - it will take you to the REALsoftware store, and as a referrer I get a small percentage.