PDA

View Full Version : What's the best way to learn programming on OS X?


grotsasha
Mar 11, 2006, 12:17 PM
As there are so many programmers here, I figured I'd ask for a bit of help and advice...

Just to tell at what point I am and a bit of background:

I made my first steps in programming approximatively at age 10. It was in Basic on a sort of a small portable calculator / computer, that I could take with me at school. So I decided I'd make it remember the timing table and a couple of other formulas. (Well, the essential part of these small programms was written by my father, but I was persuaded that I've made them by myself :) ) I also attempted to write sound sequences in Prolog (need not to guess why: my father was fiddling with it). It was quite simple, but very boring (I should recopy the same chunk of text as many times as there were notes in the piece) and the thing didn't want to play it rapid enough, so I abandonned programming and computers for quite a long time.
Until I've got a Mac (you'll be surprised) a year ago. Well, very soon I knew that I wanted to know how it works. I swallowed a couple of books on unix, read a light tutorial on AppleScript and then done a couple of tutorials on bash programming. I made the exercises and all the stuff written, but I realized soon that I don't actually need bash scripting (as I don't own a Linux installation or any complicated network). And one can't really have fun doing only exercises... Well then I've started a bit with Python (and I continue now), it is defenitevely much better and cleaner looking than the previous ones, so I plan to learn it better. My ultime goal is of course to taste a bit of Cocoa, but of course I need to learn C before that.

I've read a beginner book on C++, but the main problem, that such books require a Windows installation (that I don't have and don't want to have). I also took a short look on some C books, but they looked really scary (i.e. old and theoretical), I was also stunned looking at the first "Hello, World", that was actually a page long, so hmm... rather strange, I thought... Do I actually need to learn this to write two words to stdout?! And my concern about C (maybe an absolutely silly one) that I can actually break my computer, as I heard that you can compile pretty anything and then oups...

So my questions are coming:
I need to have some more experience to get to C. But with what language?
Can I start it after more serious Python investigation? Or learn something else after that? (one friend adviced me to learn Pascal, but then I've read more than a couple of times that it's no good and ugly). And what languages are good supported on OS X? So what do you think is the best way to continue? And if you are programming in Cocoa, what languages did you learn before that, i.e. what was your way to get there?

kolepard
Mar 11, 2006, 01:10 PM
I suggest "Learn C on the Macintosh" You can find considerably more information on it at http://www.spiderworks.com , and the specific link for that book is: http://www.spiderworks.com/books/learncmac.php

HTH

Kevin

OldVAXGuy
Mar 11, 2006, 07:27 PM
Since you've already dabbled in AppleScript, you might want to look into "AppleScript: The Missing Manual," which is a terrific introduction to that language. And AppleScript: The Definitive Guide, by Matt Neuberg (2nd Edition) has a good introduction to turning a script into an application with AppleScript Studio using Cocoa developer tools.

flip
Mar 14, 2006, 10:46 AM
Sasha, you talk about your background, but not about your goals. And that's probably what should define your path.

AppleScript is perfect to quickly write little utilities to run from the Script menu, contextual menus, folder actions, or Automator. It's the best way to add missing features to the applications you use, to create bridges between applications, things like that. It can also be used to build more complex applications, but its rather poor performances and its limited syntax make it rapidly frustrating. So if it makes perfect sense for everything that drives other applications, it's definitely not the best language to write standalone applications.

Another weak point of AppleScript is the limited GUI it provides. Apple made AppleScript Studio to give AppleScript an extensive UI and it's really great for relatively simple projects. But if you try to build a complex application, you'll quickly get frustrated again. The reason is that AppleScript Studio applications actually are Cocoa applications whose code is written in AppleScript instead of Objective-C or Java. Since Cocoa was designed to be an object-oriented environment, coding Cocoa applications in AppleScript is kind of unnatural and lots of things are impossible to do in pure AppleScript (or were the last time I tried).

C and C++ are much more powerful and run much faster than AppleScript, but the lower level at which they run implies that you have much more responsibilities as a developer. You then have to deal with a lot more things that can have adverse effects when they're not handled properly (like memory that could leak until your Mac runs out of it, and things like that). OTOH, if you want to write mainly cross platform applications and CLI tools, that would be the way to go.

Now if you want to write relatively complex Mac only GUI applications, your best choice is definitely Cocoa and Objective-C. IMO, you don't have to have a great experience in C or C++ to start learning Objective-C. Since you have some experience in C-like syntaxes, you can grab a good book (like Aaron Hillegass' Cocoa Programming for Mac OS X (http://www.bignerdranch.com/products/cocoa1.shtml)) and start from there. What you miss in C, then, I'm sure you can learn it on the way.

That's basically the path I went. I started playing with AppleScript when I got my first Mac back in System 7 ages (I was making a living as sound engineer and stage manager, by then). When I started to hit AppleScript limitations, a few years later (trying to generate webpages), I went to Frontier, which is powered by a high level language with a C-like syntax called UserTalk. After a few years, I started finding jobs as a Frontier developer and quit working in the showbiz. When I started hitting Frontier's limitations, I gave C a try for a couple of months. But I found learning it pretty boring and it looked like it was going to be a long and tedious process.

Then Mac OS X came out, providing for free all the tools you need to write Cocoa and AppleScript Studio applications. I gave up C and tried AppleScript Studio. But I ran into its limitations after a few months and decided to try the jump to Cocoa and Objective-C. I found it surprisingly easier and funnier to learn than C. And when I got some experience in Objective-C, I found that going back to C was easier too.

HTH.

(Wow, that was much longer than what I thought it would!)

grotsasha
Mar 14, 2006, 11:11 AM
Thanks a lot for your long reply.

I agree a lot on what you say about AppleScript. I don't actually want to learn it really in depth, because I know that it is just a kind of a toy for calling applications to automate some tasks. And since AppleScript relies on this applications to operate correctly, I understand without trying, that it can lead very quickly to strange results (i.e. I will never know if it's a bug in the application or mine). I knew that it is somehow possible to use AppleScript to build apps, but the idea seemed quite strange to me.

Well, my goals... Mmm..have some fun... I would really like to read and understand Obj-C code. And to write some myself just to see if it works. I always have some ideas on something that I can't find in other programms. It's always different things, that can be achieved in different ways. Of course a part of my ideas are possible to do via a scripting language. But for me it would be a lot of fun to be able to make, say, a true something in the Mac GUI. Nice looking and all that stuff.

I know, that's a long way but for me it's always fun to learn something on my own, especially languages (For the past 5 years I was also learning French and German by myself, worked quite good :) )

I'll give a look on the books recommended here. (We've got a nice and big Computer Books shop here in München, btw)

flip
Mar 14, 2006, 06:21 PM
I agree a lot on what you say about AppleScript. I don't actually want to learn it really in depth, because I know that it is just a kind of a toy for calling applications to automate some tasks.
Well, it's not exactly a toy, and I hope that's not how I made it sound because that wasn't my intention.

AFAIK, AppleEvents were the very first efficient way to get various unrelated GUI applications communicating with each others in a personal computer. And even today, it's really the best way to add features to third party applications. For example, Eudora doesn't provide a command to reveal in the Finder the files attached to a given message. When I found this out, I could have filed a feature request and waited for that feature to be implemented. Or I could have launched a script editor and taken 10 minutes to script it and make it available in Eudora's menubar and toolbar (which I did, of course). And AppleScript is only one language you can use to do that. You could do just the same in UserTalk or in JavaScript, still using AppleEvents.

And since AppleScript relies on this applications to operate correctly, I understand without trying, that it can lead very quickly to strange results (i.e. I will never know if it's a bug in the application or mine).
That's a valid point. But it didn't prevent people I know from building complex workflows driven by AppleScript to assemble books or automatically put together catalogs, for example. Even if they are slow, such systems work well enough to be still much faster than doing the same by hand, and most of the time their users wrote and maintain them themselves.

But even if you don't use it to build such automations or write GUI applications, AppleScript is still a great way to quickly write small utilities. I have tens of such little scripts that I use all the time.

Well, my goals... Mmm..have some fun... I would really like to read and understand Obj-C code. And to write some myself just to see if it works. I always have some ideas on something that I can't find in other programms. It's always different things, that can be achieved in different ways. Of course a part of my ideas are possible to do via a scripting language. But for me it would be a lot of fun to be able to make, say, a true something in the Mac GUI. Nice looking and all that stuff.
Frankly, with one or two good books I'm sure you're smart enough to put together and release your first Cocoa application in less than 5 or 6 months (it would take a bit longer to compete with applications like PF, though). Good luck! :)

grotsasha
Mar 14, 2006, 10:43 PM
Sorry for having been rude concerning AppleScript. I should not have judged something only because I heard it, and not because I tried it out in depth.

I understand though that each language has its unique advantage in some particular field. If it is not the case, the language is not much in use and dies.

Thanks for the compliment. I'll see what I can do :)

flip
Mar 15, 2006, 07:40 AM
Sorry for having been rude concerning AppleScript. I should not have judged something only because I heard it, and not because I tried it out in depth.
No need to apologise! I just wanted to make sure you don't dismiss it completely.