🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #2480

Re: Request For Comment About Handling Of Globals

#2480
From: Anton Rang
Date: Mon, 10 Dec 1990 21:40
38 lines
2510 bytes
In article <1189@ncis.tis.llnl.gov> turner@lance.tis.llnl.gov (Michael Turner) writes:
>I've explained to many programmers my view that global variables are to
>data structures what the GOTO is to control structures (worse, in many
>ways, if you ask me--I'll use the occasional GOTO, but my references to
>global variables tend to be to someone else's, not to any that I invented.)

  Global variables : data structures :: LongJmp : control structures

The problem with global variables is that they can affect anything,
anywhere in the program.  Thus, it's difficult when you see an
assignment 'FLAG = 1' to figure out what in the world this might
affect.  (Comments help, too, but....)

>When is a global necessary?  I think the answer is: almost never.

  They're almost never necessary, but they can be convenient when
working with languages which don't have nesting.  If I read in N, M,
and two N-by-M arrays, I'm likely to use a global variable to hold
this, instead of passing an extra four parameters to 90% of my
procedures.  It's sloppy, but....

  I prefer working with languages which have nested scope; in that
case, I can pass parameters in once, and use them in subprocedures
without needing to explicitly pass them.  This can be abused, just as
globals can, but often it's more clear, IMHO, than explicitly passing
parameters--it may be more clear to call a function 'edge(X,Y)' in a
test than 'edge(G,G2,N,M,X,Y).'

>Forget about GOTO-phobia, how about "`extern' variables considered
>harmful?

  And static variables!  And global error statuses!  <grin>

	Anton
   
+---------------------------+------------------+-------------+
| Anton Rang (grad student) | rang@cs.wisc.edu | UW--Madison |
+---------------------------+------------------+-------------+
Technical Details
Message-ID: <RANG.90Dec10164012@nexus.cs.wisc.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rutgers!netnews.upenn.edu!msuinfo!rang
References: <242@smds.UUCP> <PCG.90Nov16161830@odin.cs.aber.ac.uk> <252@smds.UUCP> <PCG.90Nov27153408@odin.cs.aber.ac.uk> <1990Nov30.191454.29030@newcastle.ac.uk> <1990Dec7.195140.3022@arnor.uucp> <1189@ncis.tis.llnl.gov>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rutgers!netnews.upenn.edu!msuinfo!rang
From: rang@cs.wisc.edu (Anton Rang)
Newsgroups: comp.lang.misc
Subject: Re: Request For Comment About Handling Of Globals
Message-ID: <RANG.90Dec10164012@nexus.cs.wisc.edu>
Date: 10 Dec 90 21:40:12 GMT
References: <242@smds.UUCP> <PCG.90Nov16161830@odin.cs.aber.ac.uk>
 <252@smds.UUCP> <PCG.90Nov27153408@odin.cs.aber.ac.uk>
 <1990Nov30.191454.29030@newcastle.ac.uk>
 <1990Dec7.195140.3022@arnor.uucp> <1189@ncis.tis.llnl.gov>
Sender: news@msuinfo.cl.msu.edu
Organization: UW-Madison CS department
Lines: 34
In-Reply-To: turner@lance.tis.llnl.gov's message of 10 Dec 90 18:55:53 GMT