One way would be to pass everything in as a parameter and not bother with globals. A bit idealist because you end up with tons of parameters like in the old days.
Adv: no globals
Dis: if one parameter is added, it has to be propagated all the way down to the routine that uses it.
Another way would be to create a type with all the "global" stuff in it. Declare one in the main module and pass it round as a parameter. This is more manageable. In this case all accesses to the globals will be prefixed with the item (say ggg%) so there is no need to prefix them yet again. This is basically an OO technique.
Adv: no globals
Adv: adding new variables is simple - just add it to the type and routines that use it.
Adv: doesn't suffer from propagation problems
Dis: all accesses must be prefixed with the type variable followed by %.
If you are sharing variables across several modules then make up one module with all the global decls. All the others will "use" this module. It would help if you identify the members of this module with some prefix like g_ so that anyone reading the code will know where it comes from and won't attempt to look for it locally.
Adv: adding a new global - just add it to the module and the routines that need it.
Dis: people maintaining the program must subscribe to adding the g_ prefix.
Note that on F90, all dynamic allocation must be done up front. It doesn't like allocatable parameters (at least the version I use doesn't).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.