Path: utzoo!dptcdc!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!aramis.rutgers.edu!paul.rutgers.edu!surfers.rutgers.edu!emuleomo From: emuleomo@surfers.rutgers.edu (Emuleomo) Newsgroups: comp.lang.c Subject: Re: An Ethics Question (global variables) Message-ID: Date: 17 Apr 89 16:15:56 GMT References: <1819@uop.edu> <1989Apr7.190827.4289@utzoo.uucp> <1230@l.cc.purdue.edu> <994@quintus.UUCP> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 28 > > Global variables versus parameter passing > What I HATE about global variables is that the first time you look at a function that uses it, the functions seems to work mysteriously. Futhermore, you had better be damned sure that you dont 'tamper' with those variables since they could also be used somewhere else (in another function). The RULE OF THUMB is... PASS PARAMETERS whenever you can. Believe me. It will save you countless hours of debugging time. Besides they make your functions transportable. However, I must admit that if you find yourself passing say 10 parameters to a function and maybe half of them are the addresses of variables into which you want to assign values, then you may consider using global variables. Howvever, try to keep all the routines that need to communicate with each other via global variables in the same file and declare the variables as STATIC. Another helpful trick is make the Fisrt letter of your Global Variable UPPERCASE and the rest lowercase!. This way, you can easily identify which are the global variables in your code! --Emuleomo O.O. ** The only global variable I use is a database! ** lowercase letters EXCEPT the f you want their values My first reaction in coding a function/subroutine is to pass parameters to it and let it operate on these parameters. If you are working on a large and complex so