Re: Ten Commandments for Fortran Programming?



Walter Spector wrote:

Stanislaus wrote:

Are there any code styles for Fortran? Official or not. And what do you
prefer?


Perhaps this should be an FAQ response for this newsgroup? What do others
think? (All constructive additions/deletions/commentary appreciated!)

Walt
---------------------------------------------------------------------------

Ten Commandments for Fortran Programming
comp.lang.fortran
(DRAFT v0.1)

1.) Thou shalt use IMPLICIT NONE in every program unit.


Good, but it would be better if it were the default.

2.) Thou shalt CONTAIN every subroutine and function.

Except when required to create Fortran 77 compatible libraries or libraries to be shared with other languages...


3.) Thou shalt use self-explanatory variable names.

Good, but don't go overboard. Not everybody is a blazing typist. What about naming conventions that require a prefix identifying variable type and/or other information?


4.) Thou shalt comment thy code accurately, but not excessively.

Good. Thou shalt use inline comments in order to compress source code where feasible, for example a list of variable declarations, rather than one whole line comment, one variable declaration, one whole line comment...


5.) Thou shalt honor and use the current Fortran Standard; for it
is good, and powerful, and most vendors are striving to follow it.

Can't, no compilers available.


6.) Thou shalt PARAMETERize "magic numbers". In one place.

Good, probably a module.


7.) Thou shalt use ALLOCATABLE sizing for major arrays.

Depends on who they are used...


8.) Thou shalt indent the interior of every block construct.

Good. Thou shalt indent the corresponding "end" statement at the same indention position as the "start" statement.


9. Thou shalt strive to avoid GOTO statements, POINTERs, and COMMON blocks,
unless there is no other way.

Key word "strive". Almost any application calling an OS API will require pointers. That is the vast majority of applications.


10.) Thou shalt test for, and handle, errors whenever practical; for core
dumps are bad for end-users morale.

They are bad for the application programmer's reputation also.


--

Gary Scott
mailto:garylscott@sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

Why are there two? God only knows.


If you want to do the impossible, don't hire an expert because he knows it can't be done.

-- Henry Ford
.



Relevant Pages

  • Re: compiling with cmake and xlf
    ... indicate fixed-form source and add that flag ... My understanding of xlf is that it does the opposite. ... fortran compilers regarding source file names. ... libraries are continually in conflict with various other C and POSIX ...
    (comp.lang.fortran)
  • Re: C vs. Fortran (half OT questions)
    ... I still need the power of C in system programming though. ... An example of this is the ATLAS BLAS ... fortran is probably the more natural language for things ... This was not always the case for numerical libraries, ...
    (comp.lang.fortran)
  • Re: Matlab Vectorisation Speed - How is it done in c++?
    ... Beating the performance of vectorized Matlab code is very ... Matlab makes calls to optimized C and Fortran libraries ... Use optimization level 3 on numerical code and level 2 on non- ...
    (comp.soft-sys.matlab)
  • Re: can somebody verify this C program which calls dsaupd_ ? (longish)
    ... >>>(terribly sorry for this long post which includes my two source files, ... > is NOT relevant to FORTRAN language newsgroup. ... More importantly, if your libraries compiled correctly, they were fine. ... > FORTRAN libs. ...
    (sci.math.num-analysis)
  • Re: GTK+ and Fortran 2003
    ... Install gfortran and the GTK2 development files (headers and static ... Windows: ... Select fortran. ...
    (comp.lang.fortran)