Confusion
Confusion
- Subject: Confusion
- From: email@hidden
- Date: Sun, 24 Jun 2001 13:51:29 -0400
Thanks to all who responded to my questions concerning the "*" and how
it is being used. However, I am now more confused than ever! Indeed, I
am so hamstrung by what appears to me to be contradictions in the
various answers, AND conflicting information in the alleged
documentation that I feel like I've taken one step forward and
five-or-six back. My level of befuddlement is so high that I can't for
the life of me even compose another question that might help clarify the
concepts I must be missing. For example, in the C textbook I have, "The
Art and Science of C" by Eric Roberts, the discussion on pointers begins
on page 454, where he states:
"In C, pointers serve several purposes, of which the following are the
more important:
Pointers allow you to refer to a large data structure in a
compact way. "
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.
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:
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.
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!
Brian E. Howard
Cocoa Cult Central
back to square minus six!