From: Paul Van Delst on 7 Mar 2006 17:00 Hello, I'm putting together some coding guidelines for review by folks here and I'm gathering input from a bunch of sources. I want to get some other people's opinions on a particular item. In one set of guidelines regarding USE satements I came across the recommendation to keep USE statements local and not to put them in the module header. This behaviour is the total opposite of what I do - I put all USE statements as the very first statements in modules and /none/ in the module procedures. I do so because, in my mind at least if not in practice, each procedure in that module cannot logically reside anywhere else but in that module so it makes no sense to repeat the exact same USE statements throughout. Additionally, I like being able to determine all the module's USE dependencies by looking in one place. So, without trying to start a "my way is better than your way" to-and-fro, do other folks have an opinion? Is there an accepted reason for doing something like keeping USE statements local to procedures? Should the localisation of USE statements relate somehow to the module structure? cheers, paulv -- Paul van Delst CIMSS @ NOAA/NCEP/EMC
From: Richard E Maine on 7 Mar 2006 17:14 Paul Van Delst <Paul.vanDelst(a)noaa.gov> wrote: > In one set of guidelines regarding USE satements I came across the > recommendation to keep USE statements local and not to put them in the > module header. > > This behaviour is the total opposite of what I do - I put all USE > statements as the very first statements in modules and /none/ in the > module procedures... Additionally, I like being able to determine all the > module's USE dependencies by looking in one place. I'm with you, mostly for that last reason. I regard the dependencies as one of the high-level important things to know about a module. I want to be able to see that without digging through the innards. -- Richard Maine | Good judgment comes from experience; email: my first.last at org.domain| experience comes from bad judgment. org: nasa, domain: gov | -- Mark Twain
From: James Giles on 7 Mar 2006 17:21 Paul Van Delst wrote: .... > In one set of guidelines regarding USE satements I came across the > recommendation to keep USE statements local and not to put them in > the module header. I mostly agree with this - with the obvious caveat that there are some things (named constants, type definitions, etc.) that must have scope in the entire module in order that your module variables can be declared with them. However, each module procedure should have an ONLY clause and that should list all entities that the procedure accesses. Namespace control is important. I also want some way to block host association unless you give an explicit list of those host entities you plan to access. Fortran used to have a useful characteristic: all entities in a given scope (except external procedures :-() were declared in that scope. The advantages were diluted because many things were implicitly declared, but at least those were all local. Fortran 90 and beyond have lost that property. I want it back - at least if I choose. -- J. Giles "I conclude that there are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies." -- C. A. R. Hoare
From: beliavsky on 7 Mar 2006 17:29 Paul Van Delst wrote: > Hello, > > I'm putting together some coding guidelines for review by folks here and I'm gathering > input from a bunch of sources. I want to get some other people's opinions on a particular > item. > > In one set of guidelines regarding USE satements I came across the recommendation to keep > USE statements local and not to put them in the module header. > > This behaviour is the total opposite of what I do - I put all USE statements as the very > first statements in modules and /none/ in the module procedures. I follow your practice. > I do so because, in my > mind at least if not in practice, each procedure in that module cannot logically reside > anywhere else but in that module so it makes no sense to repeat the exact same USE > statements throughout. Additionally, I like being able to determine all the module's USE > dependencies by looking in one place. > > So, without trying to start a "my way is better than your way" to-and-fro, do other folks > have an opinion? Is there an accepted reason for doing something like keeping USE > statements local to procedures? If only one procedure in a module USEs something called "foo" from another module, putting the USE inside that procedure would make clear that that is the only place "foo" is referenced. If many procedures use foo, it is convenient to put the USE at the beginning of the module. On a separate topic, I think USE statements should usually have the ONLY clause to clarify dependencies. Have you considered this matter in your guidelines?
From: Dan Nagle on 7 Mar 2006 17:40
beliavsky(a)aol.com wrote: > Paul Van Delst wrote: <snip> >> This behaviour is the total opposite of what I do - I put all USE statements as the very >> first statements in modules and /none/ in the module procedures. <snip some more> > On a separate topic, I think USE statements should usually have the > ONLY clause to clarify dependencies. Have you considered this matter in > your guidelines? I do this, usually, too. I want every name mentioned in the declarative section. It also provides a natural place when you need to use rename clauses to do a bit of namespace management, so you know the usual place for inspection when you revisit the source later. -- Cheers! Dan Nagle Purple Sage Computing Solutions, Inc. |