View previous topic :: View next topic |
Author |
Message |
DanRRight
Joined: 10 Mar 2008 Posts: 2816 Location: South Pole, Antarctica
|
Posted: Sat Jan 11, 2020 2:10 pm Post subject: Is this good programming style or it's obsolete ? |
|
|
I used it ones with older codes and it worked OK. Very convenient. No hassle at all. But is it a good style or obsolete? Tired with all these older COMMON and newer USE of modules to pass numerous variables in all these subroutines B, C ….And seems CONTAINS incorporates them all flawelessly. If Subroutine A has everything you need it just takes all what was declared in subroutine A as its own with all its COMMONs and USEs
Code: | Subroutine A
............
......…...
Call B
......…...
call C
............
CONTAINS
subroutine B
............
............
end subroutine B
subroutine C
............
............
end subroutine C
End Subroutine A
|
|
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Sun Jan 12, 2020 1:07 pm Post subject: |
|
|
Dan,
I don't like the use of contains.
My coding approach for selecting routines B and C is to localise the variables that are in use in B and C and so provide some documentation of the interface, ie what information is being imported into B then what is being exported from B. I want this interface to be clearly defined.
If I use CONTAINS, then this definition of a task and a minimum interface is no longer clearly provided.
In a similar way, the use of libraries of routines (which I have always liked) is in conflict with CONTAINS.
I also use implicit none so that all variables are identified in B and C, which assists me in documenting the interface and local variables.
The contrary case is, on a very few occasions, I have used CONTAINS to supply a utility routine (such as a clone of ddotp or daxpy) that is frequently called. This approach appears to improve the optimised performance of these routines and localises their use for cached operation, although I can't guarantee this in all cases.
I am sure there will be others that like CONTAINS, although it could promote duplication of B or C, should they perform any more general calculation.
I have not identified any suggestion that the use of CONTAINS is obsolete. |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2816 Location: South Pole, Antarctica
|
Posted: Sun Jan 12, 2020 1:47 pm Post subject: |
|
|
Great that this approach is not considered obsolete. I found it incredibly useful when using subroutines/functions B and C to read and save everything in the code. The subroutine A in my case has all variables via COMMON and USE from the entire code and messing with new declarations in B and C again would be way too much headache.
I decided to ask this question because did not believe that adding few more read and write statements could be that simple. Before it caused disproportional time compared to use of B and C with Clearwin where you can read and write data just in one click. |
|
Back to top |
|
|
|