🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #2321

Re: Pointers

#2321
From: Randy Crawford
Date: Thu, 05 Nov 1992 05:17
66 lines
3897 bytes
In article <1992Nov5.014143.15635@newshost.lanl.gov> jlg@cochiti.lanl.gov (J. Giles) writes:
>In article <Bx7oAz.7Lp@mentor.cc.purdue.edu>, hrubin@pop.stat.purdue.edu (Herman Rubin) writes:
>|> [...]
>|> Now a knife, or a gun, can be used for good or evil.  They can cause
>|> accidents.  Likewise with pointers.
>
>Yes, but pointers should be available for *voluntary use* - not 
>by compulsion.  They are *not* adequate substitutes for arrays.
>Explicit pointers are *not* needed for dynamic memory allocation.
>I would prefer *not* to have to use them for simply connected
>recursive data structures (like acyclic lists or trees).

As many have pointed out, C has arrays.  When you prefer to use an array
in C, you can and should.  To quote the bards K&R, "pointers are not arrays".
(If they didn't say that, some other wise soul surely has.)

As for using pointers for dynamic memory access or dynamically extensible
data structures -- "a rose is a rose by any other name".  In Pascal and 
Modula2 they're called typed pointers.  In Ada they're access types.  In
Lisp and Prolog, you're out of luck -- you're stuck with lists/trees and
garbage collection.

Remember, I (and I think others too) am not defending K&R C.  I much prefer
the typing of pointers made handy in ANSI C to the untyped hash they made
in K&R C.  I have little trouble with any sort of pointer "spaghettiness" 
in ANSI C.  And if that's not enough for you, there's always C++.  There
you can use other peoples' classes for all that sort of thing and keep 
your phalanges as clean as you like.

>
>Pointers are the GO TO of data structuring.  They are used to create
>spaghetti data structures in the same way GO TO is used to create
>spaghetti code.  If it's at all possible to avoid using them, don't
>use them.  As with GO TO, you only use 'em when you GOT TO.  Also,
>as with GO TO, there are ways to make your use more structured if
>you *must* use them.

In my opinion, no language leads to worse spaghetti-like data structures 
than Lisp, a language without pointers and dependent on garbage collection
to do for the programmer what s/he prefers not to do.  That's swell.  For
those (like yourself) who prefer to let the language dictate efficiency,
I suggest you steer clear of C.  That is especially true if you're unable
to devise clean tight data structures.

But don't attempt to condemn a programming language which has become the
lingua franca of the workstation world simply because it isn't all things
to all people.

>   First: in both, you should avoid having loops.  In the case of GO TO,
>   you should try not to branch backward.  In the case of pointers, you 
>   should try to avoid cyclic data structures.

[a great deal of irrelevant goto discussion deleted]

If the justification for avoiding gotos appears to you to be equivalent 
to the rationale behind pointer use, you really should get away from C as 
quickly as possible.

C isn't for everybody, just as Lisp is not.  Each has its uses, and each
cannot supplant the other.

-- 

| Randy Crawford        crawford@mitre.org        The MITRE Corporation
|                                                 7525 Colshire Dr., MS Z421
| N=1 -> P=NP           703 883-7940              McLean, VA  22102
Technical Details
Message-ID: <1992Nov5.051745.7369@linus.mitre.org>
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!spool.mu.edu!agate!linus!linus.mitre.org!boole.mitre.org!crawford
References: <1992Nov4.093545.15950@rdg.dec.com> <Bx7oAz.7Lp@mentor.cc.purdue.edu> <1992Nov5.014143.15635@newshost.lanl.gov>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.misc
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!spool.mu.edu!agate!linus!linus.mitre.org!boole.mitre.org!crawford
From: crawford@boole.mitre.org (Randy Crawford)
Subject: Re: Pointers
Message-ID: <1992Nov5.051745.7369@linus.mitre.org>
Sender: news@linus.mitre.org (News Service)
Nntp-Posting-Host: boole.mitre.org
Organization: The MITRE Corporation, McLean, VA
References: <1992Nov4.093545.15950@rdg.dec.com> <Bx7oAz.7Lp@mentor.cc.purdue.edu> <1992Nov5.014143.15635@newshost.lanl.gov>
Date: Thu, 5 Nov 1992 05:17:45 GMT
Lines: 66