4

Background

The high level overview of my situation is described here. I am breaking it apart into smaller, specific questions, such as this one, regarding extensive use of global variables in a procedural style.

Problem

In the large legacy Fortran codebase that me and some other new team members have inherited, the use of global variables by way of common blocks is extensive. There are thousands of arrays that are passed around between various modules (via include syntax).

Is there a overall strategy of working with and managing Fortran global variables and common blocks in such a massive way (1000s of shared arrays)? Are there any alternatives to global variables (e.g., database) that don't take a huge performance hit?

It seems to me that since the common block feature is part of the Fortran language (in order to make it fast by basically doing in-memory compute?), then it was intended to be used this way. However, on the other end of the argument is the advice that use of global variables is bad practice, mainly because it is hard to debug because changes to state can happen from so many different places (modules, subroutines).

Also, by alternatives to the global variable approach, I am thinking about some data layer that is not so tightly coupled like a database, where the data storage is abstracted away from the main Fortran program. This way we could be more flexible with our choice for data storage and could also interface to this data storage from other places like Python programs.

Doc Brown
219k35 gold badges405 silver badges619 bronze badges
asked Feb 12, 2020 at 15:52
2
  • 1
    Downvoters! Please be a good citizen and provide a comment to help me improve the question, so I can iterate and hopefully make it better and more useful. You can still downvote :), I just would like to know the reason why. Commented Feb 12, 2020 at 21:23
  • I guess your best bet is to introduce some (Pseudo) OO features into the Fortran codebase, like explained here, and then follow the advice about global variables in existing legacy code in this answer Commented Feb 22, 2020 at 9:31

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.