Re: Confusion
Re: Confusion
- Subject: Re: Confusion
- From: Finlay Dobbie <email@hidden>
- Date: Sun, 24 Jun 2001 19:26:24 +0100
On Sunday, June 24, 2001, at 06:51 pm, email@hidden wrote:
He then goes on to expand on this and offers three more "important"
reasons for pointers in C. For now I'm just trying to grasp this first
purpose and my problem is this: It was my understanding that one of
the prime raisons d'etre of Cocoa, and OOP in general, was to
encapsulate the bloody data in an object so that you didn't have to
deal with this pointer stuff. Why do I need an address "shorthand"
for a large data structure when I already have a better "shorthand" in
the form of an object that contains the data? Perhaps part of the
problem is that the word "pointer" is being used to describe too many
things that happen to be loosely related. Someone said that everything
is a pointer, or rather every object. Unless the definition of pointer
is extremely loose, this makes no sense to me at all. It tells me
nothing! Indeed, it smacks of tautology.
This is shorthand as far as the computer is concerned (kind of). Because
of the nature of Objective-C objects, they must always be dynamically
allocated (I don't think you know for sure how big they are going to be
when you initialize them, for one). Also, a pointer is very small, but
an Obj-C object could be very big. There are also other reasons for
using pointers to objects, which I'm not even going to attempt to
explain, since I'm not very good at that type of thing.
All a pointer is is an address in memory, in case you'd missed this in
the previous discussion.
If I declare:
NSString *myName;
I am stating that myName is of type NSString. So, in a loose sense
myName is pointing to NSString. But the important thing here, IF I
understand this, is that I'm statically typing myName to NSString to
give the compiler a heads up so that it can perhaps find an error that
might have been missed if I just declared myName thus:
myName is a pointer to an NSString object. When you do myName =
[[NSString alloc] init], you set aside some memory to hold myName, and
initialise it to be an NSString object. [[NSString alloc] init] returns
the address of where this object is located in memory.
id myName;
If I have this right, then it seems to me that calling myName a
"pointer" only dilutes the definition of "pointer" when the word is
being used to describe something that is much more TO THE POINT.
What? Sorry, you've lost me here.
I fully understand the need for a pointer in straight C to "refer to a
large data structure in a compact way," but I just don't get this need
in Objective-C when the data is within an object. I thought the idea
was to ask the object to do something with its data and return an
answer. No doubt I'm missing something here, but once again the
cryptic nature of programming documentation that seems to be de rigueur
is driving me nuts. That and the fact that most of these _teachers_
writing these expensive books I have don't seem capable of teaching
compulsive gamblers how to lose money. Memory is now cheaper than
dirt, so why are we still clinging to the overly cryptic, abbreviated,
and acronym-riddled constructs of the past? I'm just trying to control
a STUPID machine; it should not be this hard to do so!
That's not the only reason for using a pointer. Also, you seem far too
confused and messed up for me to untangle you, I'll let someone else
pick up here. pointers are not remnants of the past, they are still
useful today. Plenty of people seem to be able to understand pointers
from descriptions in a book, my guess is that you're rushing into things
without understanding the concepts behind them and then finding that
your house collapses because there are no foundations.
-- Finlay