Fortran is a general-purpose, compiled imperative programming language that is especially suited to numeric computation and scientific computing. It was originally developed by IBM in the 1950s for scientific and engineering applications.
Fortran Anti-Patterns Overview
Using GOTO Statements
GOTO
statements, which make code difficult to understand and maintain. Use structured control flow constructs like DO
loops, IF-THEN-ELSE
, and SELECT CASE
instead.Not Using IMPLICIT NONE
IMPLICIT NONE
to disable implicit typing. This helps catch typos and undeclared variables at compile time, making your code more robust.Using COMMON Blocks
COMMON
blocks for sharing data between program units. Use modules instead, which provide better type checking, encapsulation, and maintainability.Using Fixed-Form Source
Using Obsolete Features
Not Using Modules for Data Encapsulation
Using EQUIVALENCE Statement
EQUIVALENCE
statement, which can lead to undefined behavior and makes code hard to understand and maintain. Use explicit type conversions or derived types instead.Not Using Proper Array Operations
Not Using Allocatable Arrays
Not Using INTENT Attributes
INTENT
attributes (IN
, OUT
, INOUT
) for subroutine and function arguments. This documents how arguments are used, helps prevent bugs, and enables compiler optimizations.Using ENTRY Statement
ENTRY
statement, which creates multiple entry points in a single subroutine or function. This makes code hard to understand and maintain. Use separate subroutines or functions instead.Not Using Proper Error Handling
IOSTAT
) and provide meaningful error messages (IOMSG
).Not Using KIND Parameters
KIND
parameters to specify precision requirements in a portable way. This makes your code more maintainable and portable across different platforms.Not Using Proper File Handling
NEWUNIT
to get a unique unit number instead of hardcoding unit numbers. Also, always check for I/O errors and handle them appropriately.Not Using Proper Initialization
Not Using Proper Derived Types
Not Using Proper Documentation
Not Using Proper Testing