forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Is this good programming style or it's obsolete ?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Sat Jan 11, 2020 2:10 pm    Post subject: Is this good programming style or it's obsolete ? Reply with quote

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
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Sun Jan 12, 2020 1:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Sun Jan 12, 2020 1:47 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group