Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: net.unix-wizards Subject: Re: Let ME try for a new topic... (externals) Message-ID: <3952@utzoo.UUCP> Date: Sat, 9-Jun-84 17:54:55 EDT Article-I.D.: utzoo.3952 Posted: Sat Jun 9 17:54:55 1984 Date-Received: Sat, 9-Jun-84 17:54:55 EDT References: <182@itm.UUCP> <3927@utzoo.UUCP>, <535@opus.UUCP> Organization: U of Toronto Zoology Lines: 33 Dick Dunn comments: >Sorry, Danny, but I can't resist: my favorite way of dealing with >the problem is to avoid external variables. Passing information as >parameters and returned values is a much cleaner way of communicating >between different modules... Unfortunately, this has nothing to do with the issue. Parameters and global variables solve two different problems; it's comparatively seldom that you have a real choice as to which is appropriate. Please remember that parameters have limited scopes and extents (lifetimes). He's made the same mistake as several people that sent mail to me privately: he has confused the words "external" and "global". I did not say "global variables are bad", I said "external variables are bad". I never said that variables with longer lifetimes than a single function invocation are a poor idea, because often they are both necessary and appropriate. What I said was that variables that are visible all over the place, i.e. are used for "communicating between different modules", are bad. Such communication is much simpler and cleaner if it goes by a more restricted interface, i.e. function calls. I use global variables a lot. But practically all of them have the magic word "static" in their declarations, so they are visible only within the source file (the handiest definition of "module" in C) in which they are defined. The number of external variables I use, even in large many-module programs, can be counted on one's thumbs. I have experienced no trouble in working this way, and I highly recommend it. Such programs are a lot easier to understand than almost anything that needs an "externs.h" file. -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry