Style guide

Contents
implicit none always
Intent everything
Small modules
Name things plainly

implicit none always

Start every program unit with implicit none so all variables need explicit declarations.

Misspelled names then fail at compile time instead of silently becoming new variables.

program tidy implicit none integer :: total total = 3 print *, "total =", total end program tidy

Intent everything

Give every dummy argument an intent: in for inputs and out for results and inout for updated values.

Clear intent documents data flow and lets the compiler catch accidental writes to inputs.

subroutine add_tax(price, rate, total) implicit none real, intent(in) :: price real, intent(in) :: rate real, intent(out) :: total total = price + price * rate end subroutine add_tax

Small modules

Keep modules small and focused on one topic. One data type plus its helpers is a good size.

Small units are easy to test, easy to reuse, and easy to explain to the next reader.

module math_helpers implicit none contains function double_it(x) result(y) implicit none real, intent(in) :: x real :: y y = 2.0 * x end function double_it end module math_helpers

Name things plainly

Choose short plain names: count for a counter and total for a sum and rate for a ratio.

Avoid clever abbreviations. The reader should guess the meaning without opening another file.

program plain_names implicit none integer :: count real :: total count = 4 total = real(count) * 1.5 print *, "count =", count, "total =", total end program plain_names

Next: Hero roadmap: the whole course on one page

Article author: Arthur Isaev

Related articles
Fortran
Fortran course: zero to hero in 50 lessons
What is Fortran and where it runs
Install gfortran
Your first program
Program structure
Types: integer real complex logical character
Kind parameters
Operators
Conditions
DO loops
Arrays
Array sections
Character strings
Formatted IO
Files
Subroutines and functions
Modules
USE with ONLY
INTENT
OPTIONAL and PRESENT
Explicit interfaces
Derived types
Type-bound procedures
Object orientation
Operator overloading
Finalization
Allocatable arrays
Pointers in Fortran
DO CONCURRENT
Coarrays
OpenMP basics
Namelists
IEEE arithmetic
Intrinsic matrix math
Random numbers
String tools
Command-line arguments
Environment variables
error stop
Testing
Build with gfortran and make
Debugging
C interoperability
From fixed form to free form
Numeric models
Performance
Modern Fortran tour: 2008, 2018, 2023
Capstone: stats tool
Capstone: 1D heat equation
Style guide
Hero roadmap: the whole course on one page
Install gfortran on Windows 11
Install gfortran on Ubuntu
Install gfortran on Rocky Linux
Install gfortran on macOS
Install gfortran on FreeBSD
Fortran in Docker
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: