home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gumby!yale!yale.edu!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.lang.misc
- Subject: Re: Pointers
- Date: 5 Nov 1992 18:58:16 GMT
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 35
- Message-ID: <1dbqs8INN7qo@early-bird.think.com>
- References: <1992Nov4.093545.15950@rdg.dec.com> <Bx7oAz.7Lp@mentor.cc.purdue.edu> <1992Nov5.014143.15635@newshost.lanl.gov>
- NNTP-Posting-Host: telecaster.think.com
-
- In article <1992Nov5.014143.15635@newshost.lanl.gov> jlg@cochiti.lanl.gov (J. Giles) writes:
- > Second: in both, you should avoid aliasing. In the case of GO TO,
- > you should avoid branching to the same label for many disparate
- > reasons. In the case of pointers, you should try to avoid have
- > two pointers to the same thing *at all*.
-
- That's a silly guideline. The most common reason to use pointers is
- precisely *because* you need multiple references to the same data. In
- object-based programming, an object may be in different relationships with
- other objects, and relationships are usually implemented as pointers
- between objects. For instance, in a family tree model, a person might have
- pointers to its parents, children, and siblings; any particular person is
- likely to be referenced by the children array of two parents and a parent
- pointer of some children.
-
- Your guideline suggests that the main reason for using pointers is to avoid
- copying data (e.g. passing arguments by reference by passing a pointer).
- While pointers are certainly useful for this (in languages that don't
- provide better mechanisms, such as C++'s references), I hardly consider it
- the raison d'etre of pointers.
-
- In another article, someone pointed out that the most spaghetti structured
- code tends to be Lisp, which doesn't have pointers. While it's true that
- Lisp doesn't have distinct pointer values, in some sense every value is
- conceptually a pointer value, because of Lisp's object-based nature (most
- Lisp dialects allow optimizations for numeric values that that allow them
- to be treated as non-objects, though). The only difference between Lisp
- and other languages in this regard is that Lisp doesn't have an explicit
- dereference operator, as dereferencing happens automatically. The Lisp
- expression (car a) is analogous to the C expression (cons *)a->car.
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-