Writing fortran robust and "modern" code
Posted
by Blklight
on Stack Overflow
See other posts from Stack Overflow
or by Blklight
Published on 2010-05-03T14:13:26Z
Indexed on
2010/05/03
14:18 UTC
Read the original article
Hit count: 356
In some scientific environments, you often cannot go without FORTRAN as most of the developers only know that idiom, and there is lot of legacy code and related experience. And frankly, there are not many other cross-platform options for high performance programming ( C++ would do the task, but the syntax, zero-starting arrays, and pointers are too much for most engineers ;-) ). I'm a C++ guy but I'm stuck with some F90 projects.
So, let's assume a new project must use FORTRAN (F90), but I want to build the most modern software architecture out of it. while being compatible with most "recent" compilers (intel ifort, but also including sun/HP/IBM own compilers)
So I'm thinking of imposing:
- global variable forbidden, no gotos, no jump labels, "implicit none", etc.
- "object-oriented programming" (modules with datatypes + related subroutines)
- modular/reusable functions, well documented, reusable libraries
- assertions/preconditions/invariants (implemented using preprocessor statements)
- unit tests for all (most) subroutines and "objects"
- an intense "debug mode" (#ifdef DEBUG) with more checks and all possible Intel compiler checks possible (array bounds, subroutine interfaces, etc.)
- uniform and enforced legible coding style, using code processing tools
- C stubs/wrappers for libpthread, libDL (and eventually GPU kernels, etc.)
- C/C++ implementation of utility functions (strings, file operations, sockets, memory alloc/dealloc reference counting for debug mode, etc.)
( This may all seem "evident" modern programming assumptions, but in a legacy fortran world, most of these are big changes in the typical programmer workflow )
The goal with all that is to have trustworthy, maintainable and modular code. Whereas, in typical fortran, modularity is often not a primary goal, and code is trustworthy only if the original developer was very clever, and the code was not changed since then ! (i'm a bit joking here, but not much)
I searched around for references about object-oriented fortran, programming-by-contract (assertions/preconditions/etc.), and found only ugly and outdated documents, syntaxes and papers done by people with no large-scale project involvement, and dead projects.
Any good URL, advice, reference paper/books on the subject?
© Stack Overflow or respective owner