AKMA's Random Thoughts

February 28, 2003

So There!

Ha! You thought I couldn’t finish it—don’t try to prevaricate, I know you doubted me. But I just dropped it in the email to my editor, so I have one fewer obligation hanging over my head. (A couple of overdue book reviews, an essay that's not due till, I don’t remember, December or something, and, ahem, three complete book manuscripts of which I’ve started two.)

Now, on to Rochester for the weekend. Got to remember to run my aggregator before I leave, so I can catch up on the web while we ride the train. . . .

Posted by AKMA at February 28, 2003 03:32 PM | TrackBack
Comments

Three cheers and a tiger for you! I'm really glad you were able to finish before you left. Now you can enjoy your weekend travels with a clear conscience. Have a great trip!

Posted by: Jane at February 28, 2003 04:19 PM

Let's take a moment to reexamine that. What we've done here is create two variables. The first variable is in the Heap, and we're storing data in it. That's the obvious one. But the second variable is a pointer to the first one, and it exists on the Stack. This variable is the one that's really called favoriteNumber, and it's the one we're working with. It is important to remember that there are now two parts to our simple variable, one of which exists in each world. This kind of division is common is C, but omnipresent in Cocoa. When you start making objects, Cocoa makes them all in the Heap because the Stack isn't big enough to hold them. In Cocoa, you deal with objects through pointers everywhere and are actually forbidden from dealing with them directly.

Posted by: Julius at January 13, 2004 03:27 AM

Let's take a moment to reexamine that. What we've done here is create two variables. The first variable is in the Heap, and we're storing data in it. That's the obvious one. But the second variable is a pointer to the first one, and it exists on the Stack. This variable is the one that's really called favoriteNumber, and it's the one we're working with. It is important to remember that there are now two parts to our simple variable, one of which exists in each world. This kind of division is common is C, but omnipresent in Cocoa. When you start making objects, Cocoa makes them all in the Heap because the Stack isn't big enough to hold them. In Cocoa, you deal with objects through pointers everywhere and are actually forbidden from dealing with them directly.

Posted by: Ferdinand at January 13, 2004 03:27 AM

For this program, it was a bit of overkill. It's a lot of overkill, actually. There's usually no need to store integers in the Heap, unless you're making a whole lot of them. But even in this simpler form, it gives us a little bit more flexibility than we had before, in that we can create and destroy variables as we need, without having to worry about the Stack. It also demonstrates a new variable type, the pointer, which you will use extensively throughout your programming. And it is a pattern that is ubiquitous in Cocoa, so it is a pattern you will need to understand, even though Cocoa makes it much more transparent than it is here.

Posted by: Nathaniel at January 13, 2004 03:27 AM

A variable leads a simple life, full of activity but quite short (measured in nanoseconds, usually). It all begins when the program finds a variable declaration, and a variable is born into the world of the executing program. There are two possible places where the variable might live, but we will venture into that a little later.

Posted by: Cornelius at January 13, 2004 10:10 AM

The rest of our conversion follows a similar vein. Instead of going through line by line, let's just compare end results: when the transition is complete, the code that used to read:

Posted by: Chroferus at January 13, 2004 10:11 AM

When Batman went home at the end of a night spent fighting crime, he put on a suit and tie and became Bruce Wayne. When Clark Kent saw a news story getting too hot, a phone booth hid his change into Superman. When you're programming, all the variables you juggle around are doing similar tricks as they present one face to you and a totally different one to the machine.

Posted by: Melchior at January 13, 2004 10:11 AM