Silverfrost Forums

Welcome to our forums

Is this good programming style or it's obsolete ?

11 Jan 2020 1:10 #24853

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

Subroutine A
............
......…...
Call B
......…...
call C
............  

    CONTAINS
    subroutine B
    ............
    ............
    end subroutine B

    subroutine C
    ............
    ............
    end subroutine C

End Subroutine A 
12 Jan 2020 12:07 #24854

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.

12 Jan 2020 12:47 #24855

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.

Please login to reply.