Seeking a bridge languate between PHP and Objective-C
August 28, 2010 4:05 PM   Subscribe

I, like millions of others, want to learn Objective-C so I can write an iPhone app that will instantly sell ten million units and allow me to retire by year's end. I bought three books to help my on my way (1, 2, 3). Being well versed in web programming, I figured this would be a challenging, but possible transition. Boy oh boy was I wrong. Please help me find a bridge between my procedural PHP ninja skillz and the fantasical (and ever-frustrating) world of OOP C languages.

I've been a backend developer for the last 8 years, and would consider myself at a near-expert level with the "big three" web languages/tools: PHP, mySQL, jQuery. I work with these web technologies every single day, and prior to diving into these books, thought myself a decent programmer. I had no idea how vastly different the two sets of knowledge were.

So, how can a PHP guru transition into the world of Objective-C? It appears that jumping right in isn't the answer; at least for me. The part about memory allocation is where I'm getting stuck, and I'm sure all the topics past that section would be even more confusing. Are there any "bridge languages" you can suggest? Java? Regular old C? Something else?

PS - I've also looked at PhoneGap, which bridges the technologies I already know with the iPhone SDK, but it's not as advanced as I would like. And besides, if I'm going to write an app, I want to do it right and learn the native language.

posted by (bb|[^b]{2}) to Computers & Internet (20 answers total) 25 users marked this as a favorite
I had the same issue when I tried to learn Objective-C, but my background is in Java. So my guess is that that is not the best approach.
posted by telegraph at 4:10 PM on August 28, 2010

You should learn C first. For someone who knows C, Objective-C is simple to learn, as it is just an extension to C that adds objected-oriented and messaging constructs.

Cocoa, the (very large) library that lets you write beautiful iPhone and Mac apps, will take longer to learn. There are a lot of subtleties to Cocoa that you need to understand to write apps that behave in a Mac-like way. The books that you bought will be very helpful when it comes to learning Cocoa, but without the solid grasp of pointers and memory management that you'll need to acquire to learn plain old C, you won't be able to understand Objective-C/Cocoa as well as you'd like.
posted by jordanlewis at 4:14 PM on August 28, 2010 [4 favorites]

Yes, C. I hadn't seen Objective-C before I wrote an iPhone app but had a C background and didn't find it too hard as a result.
posted by galaksit at 4:21 PM on August 28, 2010

Like everybody else, I'm here to tell you that you must learn C first. C (and assembler) teach a close understanding of the computer itself. This is mandatory knowledge when working with tiny computers like the iPhone.

It might also help to play a little bit with ruby. Not ruby on rails. Just the interactive irb program that's already installed on your Mac (the one I assume you have for iPhone dev). Ruby is designed with a similar object model and message passing structure. Ruby is far less constrained than ObjC, but they have a similar fundamental structure--based on smalltalk, btw.

I also suggest that you step back and read up on classical programming. Like, seriously go all the way back to hello world in C. Implement some of the basic data structures (tree, hashtable, vector, linked list). Do some of the sorting and searching algorithms. Just, like, learn how to program when you're the one juggling objects and managing where shit actually resides in memory.

You need to learn what a computer is like, as opposed to what apache mod_php is like. And C and ruby are the languages to do it in.
posted by Netzapper at 4:44 PM on August 28, 2010 [1 favorite]

Thirding the suggestion for learning C. PHP is too much like Perl, and neither PHP nor Perl have enough similarity with C to help you easily transition.

Also, if you have more specific Objective C / iPhone framework questions, you can bring them to Stack Overflow and the Apple Developer Forums.
posted by Blazecock Pileon at 5:07 PM on August 28, 2010

I'm still working on Cocoa touch, using the Beginning Iphone 3 Development book you mentioned, but I have the same background and here was my path:

Learn C on the Mac

Programming Objective-C (the Apress book wasn't working for me)

Now I'm on the Apress Beginning Iphone 3 book, and will probably cycle through some of the rest in that series.

I still think I'll probably use the books as a guide as I get through making my own apps, as there are a lot of commands I can't imagine I'm expected to remember just yet.
posted by backwards guitar at 5:53 PM on August 28, 2010 [1 favorite]

nthing C - and for the C beginner there is a brilliant guide in getting started with C over at reddit - well worth a look

Also - leaning objective C is a noble pursuit - but gaining a good grasp of C will transform the way you program.
posted by the noob at 6:03 PM on August 28, 2010

In your quest to learn C one of the most valuable resources is the comp.lang.c FAQ which covers all of the usual gotchas that people run into. C has a LOT of sharp edges that can draw blood if you're not careful.
posted by Rhomboid at 6:06 PM on August 28, 2010 [1 favorite]

C will help you somewhat, but most of the second-wave instruction you get about pointer allocation/juggling is 75% not necessary. (It is important to know pointer arithmetic and in general how pointers are made, but the majority of Obj-C coding is not pointers, it is with allocated objects.)

Cocoa's memory management is based on pointers, yes, but those pointers are objects that are managed almost exclusively via calls to alloc, retain and release, with side dishes of create... and autorelease. You must master this allocation idiom to be a successful iPhone developer. If you do not embed this idiom into the core of your essence, you will not only fail, but you will fail screaming in a huge furball of crashpoints entirely unrelated to where your bugs are.

Once you do master object management, however, your challenge becomes longer but easier: learning the Cocoa API. It is vast, but fairly well structured. The key here is, once you've reviewed lots of sample code, to start with a single sample app as a good "starter culture" for your app and then modify it bit-by-bit to do what you want. As you implement each new feature, you'll learn about the APIs needed to make it happen -- with a working app only a few minutes away from each change.

If you want to make a shit pile of money in the App Store, programming skill counts for precisely dick. Your app must work, yes, but everyone's app works. You must have marketing/PR support out the wazoo in order to get the coverage needed in the blogs and press, and hope your app gets picked up as an "app of the week" by Apple.
posted by seanmpuckett at 6:08 PM on August 28, 2010 [2 favorites]

Get a copy of K&R 2nd edition. It's about a three-day read.
posted by orthogonality at 6:17 PM on August 28, 2010

Everybody interested in learning C should have K&R, naturally, but for my money Harbison & Steele is a better book. Get both.
posted by flabdablet at 6:25 PM on August 28, 2010

^^ Wonders how many of the people telling him to develop in C are actual iPhone developers.

I took a year of C++ classes. I can't do anything particularly useful with it (after all that), but PHP was ridiculously easy to learn afterward (Hell, if you have the function reference handy, you basically know PHP if you know C)

No idea how it is in the reverse, nor am I sure if the "academic" approach to learning C is completely appropriate here. As with any language, the "building blocks" approach is helpful. Start with "hello world," and develop incrementally complex applications from there.
posted by schmod at 6:52 PM on August 28, 2010

Read up on "classical programming" techniques? He's writing an iPhone app, not grinding out an assignment for CS Theory 202. If ObjC is so simple after C, why not cut to the chase and learn ObjC first with a book that assumes no C knowledge, like "Programming in Objective-C" by Kochan? It's not an entirely novel language; learning ObjC will involve learning C, no matter what route he takes.

Most of these answers sound less like "How to learn Objective C for iPhone development, for a web app developer" and more like, "How to begin studying computer science with C." These are not practical routes if he just wants to make iPhone apps.
posted by mnemonic at 7:15 PM on August 28, 2010

Did you read the introduction to Objective-C PDF from the Apple developer site? It's surprisingly good.
posted by ecurtz at 7:25 PM on August 28, 2010

I'm going to recommend not C, but C++. Get a 'teach yourself C++ in 19.5 days' book and read it. Don't pay attention to the syntax so much as the object-oriented concept. This is just for background, as I've found that C++ for morons books tend to be a bit more heavy on the object concept than the objective-c books. The latter tend to jump right in to code syntax very quickly.

Then. I like this book. It walks you through not only the objective-c language, but XCode and the interface builder, plus enough of a tour of the foundation frameworks to get you at least knowing what's there and how to read the documentation. The examples have you use the frameworks the way you would really do it on your own, not create everything from scratch. You can write surprisingly functional applications with very little typing in of code. Examples are easy to follow. Specifically, I thought the section on alloc, retain, release, and autorelease was very good, starting with a working example and then incrementally improving it using these techniques while explaining what was going on.

It's hard to say that it's the perfect book for a beginner, since I have whatever background knowledge picked up from years of casual interest, but I'm not a pro by far, and I think this one's good.
posted by ctmf at 8:18 PM on August 28, 2010

Most of these answers sound less like "How to learn Objective C for iPhone development, for a web app developer" and more like, "How to begin studying computer science with C." These are not practical routes if he just wants to make iPhone apps.

His iPhone apps will suck and crash if he doesn't understand what's going on under the hood. Going straight to objective-C and Cocoa is like trying to eat a Turkey by putting one end in your mouth and pushing as hard as possible.

Working through K&R is like carving the turkey first.
posted by fatbird at 10:32 PM on August 28, 2010 [4 favorites]

I know nothing about anything, but what about hooking up with someone who does know this already and collaborating? I often learn better by assisting someone experienced than I do from books.
posted by serazin at 11:49 PM on August 28, 2010

If you problem in the OOP, learning C isn't going to help a great deal. If you know PHP already then C shouldn't be much of a problem - if frustratingly limited (obviously you can do almost anything you can do in PHP but it isn't already coded into a nice neat time-saving function). Since you're most familiar with PHP, I'd recommend learning the concepts of OOP in PHP - which has had OOP capabilities for many years now. They may not be perfect, but its a start and will help you get to grips with many of the key concepts.

You might also want to take a look at TOM (thoroughly obedient moron) it teaches programming at a very low level. My teacher gave it to me at school to teach me discipline (I think he was mostly just jealous that I didn't have to queue up with a punch card and come back a week later to find out if my program worked - I could just hit 'run' and see if it worked) With Tom you really have to plan everything carefully because your program instructions each take 1 'block' of memory and you have to make sure to leave enough room for your instructions before assigning 'blocks' to put your data in.
posted by missmagenta at 5:53 AM on August 29, 2010

I've written in assembly language, C, C++ and Obj-C. Skip the intro languages. With all of the resources and examples on the web, if you can't go directly into Obj-C, you don't have the chops to be a developer.
posted by digsrus at 9:39 AM on August 29, 2010

Also look into Stanford's free CS 193P course materials, which teach an introduction to iPhone development.
posted by Blazecock Pileon at 1:38 PM on August 29, 2010

« Older site ok?   |   One passport or two? Newer »
This thread is closed to new comments.