Proper use of modules in Fortran

后端 未结 4 1208
旧巷少年郎
旧巷少年郎 2020-12-03 06:32

I work with FORTRAN a lot, but I never had formal instruction in the proper way to write source code. I currently use modules to store global variables, but I understand yo

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 06:47

    Moving related functions, subroutines and variables to their own modules improves the maintainability of a program. Later on when you have to update part of it, you don't have to go digging through a single source file with tens (or hundreds) of thousands of lines of code and can just open up the relevant files.

    Of course, you're probably thinking that you can just use your editor's search function to find the relevant subroutine, but after a few months of letting the code sit alone, you'll probably quickly find that you can't quite recall the name of subroutines or how they fit together. Having them grouped nicely helps a lot with that.

    Moving subroutines and functions into a module also improves compilation speed if the compiler only has to rebuild a single module instead of the entire program.

提交回复
热议问题