Re: MODULEand USE versus Argument Passing



E. Robert Tisdale wrote:

(snip)

Global variables are *always* a bad idea.
Never pass function arguments through modules or common storage.

There is an old saying that goes something like "All generalizations are bad, including this one."

I would agree that global variables are often overused.
There are cases where the whole program revolves around certain
variables, usually arrays. In those cases, it sometimes makes
sense. COMMON, though, requires compile time dimensions which isn't
so convenient in many cases. In C one would use a global pointer variable. I am not sure that Fortran allows either pointers or
ALLOCATABLE data in COMMON, but it might.


The general rule that the code should be written so that it
is easiest to understand still applied.  Sometimes that means
global variables.

-- glen

.



Relevant Pages

  • Re: When will this ng come to accept that Fortran needs to go "back to the future" ?
    ... Gary Scott wrote: ... It's programming with global variables again -- only with an additional ... the prior generation of models -- programmed with COMMON ... This programming style in and of itself is not bad. ...
    (comp.lang.fortran)
  • Re: common from fortran77 to fortran 90
    ... modules as a simple-minded replacement of common blocks are ... there are cases where global variables are fine and ... When, for example, the app is simulating something like an ...
    (comp.lang.fortran)
  • Re: Subroutine question
    ... Variables in common, like variables in modules, are known only where the common or module is referenced. ... and common block names. ... But there are no global variables in Fortran. ... In many languages structure element ...
    (comp.lang.fortran)
  • Re: globa variable for windows C# application
    ... General, all common things locates in separate namespace for project, smth ... As Vadim mentions you need to locate separate class for global variables, and put it in your common namespace ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: MODULEand USE versus Argument Passing
    ... >> Never pass function arguments through modules or common storage. ... > There is an old saying that goes something like "All generalizations ... > I would agree that global variables are often overused. ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)