The House of Witten

Wednesday, April 27, 2005

More Cocoa

So here is the current state of things. I ran through that tutorial. Lovely. I also borrowed "Cocoa Programming for Mac OS X" by Aaron Hillegass from the library, and have started reading that. Sadly, this has freaked me out a bit, since you are rather quickly introduced to the idea of Cocoa's memory management approach, which involved reference counting, something I have no experience with. This includes the need to retain and release objects that you are using, and the idea of autorelease, which I don't really understand yet. The idea is that when an object is created (using alloc and init) it has this internal reference counter that is incremented. So long as this value is not zero, the object sticks around. As soon as it drops to zero (the release command decrements the counter by 1 each time it's called), the object is deallocated. Seems easy enough. The hard thing to learn is when this internal reference thing is incremented. Evidently, when an object is added to an array, the object's reference count is incremented, and when that array is destroyed, the reference count of each object in that array is decremented. This gets confusing though (you really need to read the book to get why), since you must release an object right after you add it to an array, to avoid a memory leak that will arise from the extra reference that was made when the object was first allocated.

Then there's other stuff dealing with objects and scope. If you have some function that assigns some object to some other object, and since everything is dealt with by reference, there is a need to both release an object before leaving the current function (going out of scope won't kill it, since only the pointer will be deallocated, not the memory/object that it points to), and also to retain it so that the assignment will work (you can't assign one object to another if the source object has just been deallocated due to issuing a release). Anyway, to get around this problem you use autorelease, but I don't yet understand when exactly autorelease kills the source object. Maybe as I read on in the book it will become clearer, but for now I don't really get it (I understand why it's needed, and the whole retain and release thing, but not this autorelease thingy). There's also this NSAutorelease object called pool that seems to be relevant, but again, I'm not yet sure why. I'm about to read a webpage that might clarify things (http://www.cocoadev.com/index.pl?RetainingAndReleasing), and I'll post my progress as in a bit.

On a side note, there is this other cool aspect of Cocoa called bindings, which I'm also just starting to understand. The big picture idea is that the interface (created with interface builder) can do a lot of stuff on it's own, without the help of any so-called "glue code." Things like an slider changing the value of a text field, or a color picker changing the color of some text, can all be done without any actual code. This is quite cool, but again, I don't get it yet (I need to run through this other Apple tutorial)

Cocoa and Objective-C

So I want to learn how to program on the Mac "for real," which, sadly, means pretty much starting from scratch in that I need to learn Objective-C and all this other Cocoa (was OpenStep was NextStep) stuff.

So here's my starting backround. I know how to program, in the most abstract sense. I've taken classes on C++ (so I also know C), and used to do Mac stuff with Think Pascal back in college (I graduated in 1998 from Haverford College). I'm an expert at the totally useless art of Lingo (Macromedia Director's scripting langauge) programming, which is an object oriented language that is frighteningly loosely typed (this can sometimes be very annoying, such as when you think you're dealing with a float, but the value has been cast to an integer). I know Javascript (although not that well, since it is the world's most painfully thing to debug), and some Perl (which I learned for some simple CGI and text processing stuff). I also know Java to the level that I could figure anything out if I had a need for it (I've never needed to use AWT or Swing, and never tried since it looks like such a painfully way to do GUI design), but well enough that I appreciate the joys of automatic garbage collection, and how making everything an object can sometimes be annoying.

I also took at shot at learning Carbon a few years back, but gave up since the Apple documentation was far too annoying to work with. It also always seemed like there was some secret subset of C that one needed to know that was never explained (things like "static pascal," which I never understood, but were thrown around in sample code like everyone should know what a static pascal type was). Also, doing a GUI in Carbon was just as hard as in Java (well, actually much, much harder), and never appealed to me since I could code up a nice, working GUI in Director or RealBasic in 1/100th the time it would take using Carbon (this is a recurring grip of mine - you always need to choose between a "slow" interpreted language-based IDE like Director or RealBasic, or get the speed you want, but contemplate suicide when trying to make the GUI). I also hated all those damn pointers used in Carbon programming. I have nothing against pointers (which is a good thing since every object in Objective-C is a damn pointer), but they were so interspersed as parameters in function calls that it would take hours to figure out what information was actually being passed to a given function. I just never had the patience to stick with it.

I should mention a quick thought on Java here. Java is pretty damn cool, if they had an easy way to make a GUI (I believe there are development tools for this, but I never bothered to play with them), and if they had real support for graphics, video and audio. I believe that it's still the case that you can't play an mp3 file from within Java without jumping though a lot of hoops (or using QTJava, which may not be supported beyond 2 weeks from yesterday). Whenever I wanted to do something "fun" with Java (not just data crunching), I would run back to Director, where media support was outstanding. I built a pretty nifty dual mp3 playing DJ program that supported multiple sound cards several years back using Director, which would have taken me years using Carbon, and wasn't even possible with Java (multiple sound outputs? Be happy you can even play any sound at all). So that's my grip with Java.

But back to Cocoa. So the other day, I decided to run myself through the Cocoa tutorial on Apple's developer website. They run you through making a pretty lame currency converter application, which I did. The neat things was, however, that I finally got to see what the heck Interface Builder was good for (sexy, easy GUI design), and the basics of Objective-C (not a very hard language, once you start to understand the whacky syntax - what the heck is myString = @"Hello world" all about?). I realized the potential ease with which one could make some cool software using Interface Builder and all the Cocoa frameworks. And then I realized that with the release of Tiger there was going to be all these new Framewords for accessing the cool features of Tiger from Objective-C. I was especially excited about Core Image, Core Video and Core Audio (also related to QTKIT, the Quicktime Objective-C interface), since they would allow me to do the "fun" things I like so much, without all the pain of Carbon, or the slowness (and possible obsolecence) or Director or RealBasic.

So I decided it was time to really get into learning Cocoa and Objective-C, even though the Apple market is a total unknown, and this skill set might become completely useless (like it is now) in a few years. On the other hand, if Apple can run with this iPod halo effect, and make inroads into the Windows world, maybe there will be a demand for Cocoa programmers in the near future (do a Monster.com search for it right now, and you might find 3 jobs that mention Objective-C. Compare that with a search for C#...). And that's what I'm doing. More on this in the next post...

As an aside, I'm a bit freaked out by the fact that when I spell checked this post, there were not mis-spellings. This just doesn't happen to me. Weird.

Oh look, it's post #2

So here goes post #2. How terribly exciting.

I figure it would be best to set out a few goals for this little web-wonder, just to keep me motivated. So here they are:

1) Blogging about learning Cocoa and Objective-C: This should be fun, assuming that I don't give up too soon into the process. I'll add another post after this one to describe the status of this lil' adventure.

2) Blogging about Satan's human incarnation: Well, this won't really be blogging, more of an online documentation of the joy that was my "separation" from my PhD advisor. I'll be posting all the emails back and forth, and any other rants that strike my fancy. The fun part will be keeping it all anononymous, since I want to avoid engaging in anything that might appear to be libel. Of course, libel requires that what I put online is defamatory, in that it portrays Satan's son in a "false light." Can you really do that when someone is a child of the devil? I don't really think so, but I'll keep it anonymous anyway, just in case.

3) Blogging about looking for a job: This won't be fun, since the process already sucks, but blogging about it might prove theraputic. And besides, I really like to whine.

4) Blogging about whatever else I feel like

Friday, April 22, 2005

Let the Games Begin

Time to start blogging, if for no other reason than as free psychopherapy.

So, what sucked today?

It was rainy and overcast (like yesteday).

I checked online and found that I probably won't be asked to interview for the Columbus (Easton) Mac Genius position ("The following positions are no longer available..."). Not a big shocker, since I have no real retail experience, save for a 3 month run at the Gap one summer 7 years ago. Still, it pisses me off, since I hate rejection, and despite the fact that the paultry $15/hour they offer employees would have pissed me off even more.

I found out that other people have already started to receive Tiger, but that our order never went through, and the purchasing person's office was mostly detroyed by Thursday's fire. Why do I want Tiger so badly? Why, to allow me to procrastinate even more. I can spend weeks learning how to program my pathetic attempt at a software eye tracker using CoreImage. I figure it's about time that I dedicate myself to learning how to use Cocoa and Objective-C if I really want to embrace Mac programming. Director will be dead soon, Flash is annoying, and I loathe Windows with a passion. Too bad no one wants to hire Objective-C/Cocoa programmers. I've read online that there may be a market for such skills if the Mac continues to thrive off the iPod halo effect, but who knows. The Cocoa frameworks certainly look like the are very useful for rapid application development. I'll have to see what happens.

We're broke. I overlooked a car payment this month, and so it turned out that we were $273 in the hole, once all the wonderful tax checks had are cashed. Wonderful. How did we fix it? Using those "screw them while they're down" credit card convinience checks you get in the mail all the time. A wee $273 loan. And so we begin our decent down the slippery slope. It actually isn't that bad, since they only charge a 4% fee ($8.19) and the interest for a month only runs $4.79. Thirteen bucks to avoid begging our parents for a loan is certainly worth it. Of course, unless my ass gets a job soon, well need to use a few more of those checks over the next few months, since "our" income isn't matching our debt (thank you taxes!).