Skip to content

Commit 704be6a

Browse files
committed
Add initial Top 10 Recommendations
1 parent ceb0e66 commit 704be6a

11 files changed

+322
-0
lines changed

README.md

+137
Original file line numberDiff line numberDiff line change
@@ -1 +1,138 @@
11
# Top 10 Recommendations for Fortran Modernization
2+
3+
Modernizing Fortran codebases is a crucial step toward improving code quality
4+
and ensuring maintainability. It helps developers uncover hidden bugs and
5+
reduces the risk of introducing new errors during development. Additionally,
6+
these efforts support modern compilers and tools in generating optimized code
7+
and identifying potential issues early. Ultimately, modernization boosts
8+
developer productivity and enhances code robustness.
9+
10+
## Context and motivation
11+
12+
This project is inspired by the [OWASP](https://owasp.org/) community-led
13+
initiative, which regularly publishes the most relevant Top 10 Secure Coding
14+
Recommendations. These are widely adopted by the industry to help developers
15+
avoid common security vulnerabilities. The OWASP initiative thrives on
16+
collaboration and knowledge sharing through platforms like their [GitHub
17+
repository](https://github.com/OWASP/Top10).
18+
19+
Beyond OWASP, various open catalogs provide comprehensive collections of checks
20+
(rules) to help ensure secure coding practices. Each check describes specific
21+
scenarios and necessary actions, offering extensive documentation, example
22+
codes, automated code analysis tools, and references to other resources.
23+
Notable examples include [SEI CERT
24+
C](https://wiki.sei.cmu.edu/confluence/display/c) and
25+
[CWE](https://cwe.mitre.org/).
26+
27+
Building on these foundations, this project aims to start a similar
28+
community-driven initiative focused on modern Fortran software development.
29+
Leveraging the existing [Open Catalog on Best Practices for Modernization and
30+
Performance](https://github.com/codee-com/open-catalog/), we seek to establish
31+
a dedicated set of Top 10 Recommendations and related checks to address the
32+
specific challenges of Fortran Modernization.
33+
34+
Modernizing Fortran code encompasses updating and maintaining legacy Fortran
35+
codes (e.g., F77, F90) with extensive development histories. It also involves
36+
refactoring existing Fortran codes to leverage the features of the latest
37+
Fortran standards (e.g., transitioning from F90 to F23).
38+
39+
## Methodology
40+
41+
To develop the Top 10 Recommendations for Fortran Modernization, we adopted a
42+
comprehensive and community-focused approach. First, we conducted an extensive
43+
review of existing resources on the topic to identify an initial draft of the
44+
most recurrent recommendations. These were later discussed with the Fortran
45+
development community to collect insights and feedback (e.g., in Fortran
46+
Discourse
47+
[[12](https://fortran-lang.discourse.group/t/our-initiative-to-publish-the-fortran-lang-top-10-recommendation-for-fortran-modernization-is-it-really-new-or-even-feasible/7774)]),
48+
which were crucial for shaping the final proposal.
49+
50+
The presented Top 10 Recommendations are prioritized to guide developers
51+
through a progression of modernization efforts. Each recommendation is detailed
52+
with specific checks that describe actionable steps, including examples of
53+
before and after code snippets, the rationale behind the changes, and links to
54+
further reading.
55+
56+
To ensure the recommendations remain relevant and comprehensive, we plan to
57+
continuously review community input and update the guidelines as the Fortran
58+
standards evolve and new best practices emerge.
59+
60+
## Top 10 Recommendations
61+
62+
1. [Strict compliance with modern Fortran
63+
standards](Recommendations/R1_ModernStandardCompliance.md).
64+
65+
2. [Declare procedures in modules](Recommendations/R2_ProceduresInModules.md).
66+
67+
3. [Restrict data visibility with
68+
modules](Recommendations/R3_RestrictDataVisibility.md).
69+
70+
4. [Improve dummy arguments
71+
semantics](Recommendations/R4_ImproveDummyArguments.md).
72+
73+
5. [Improve data type consistency and
74+
management](Recommendations/R5_ImproveDataTypes.md).
75+
76+
6. [Avoid legacy control-flow
77+
constructs](Recommendations/R6_AvoidLegacyControlFlow.md).
78+
79+
7. [Enhance source code semantics](Recommendations/R7_EnhanceCodeSemantics.md).
80+
81+
8. [Adhere to code conventions](Recommendations/R8_CodeConventions.md).
82+
83+
9. [Adopt modern development
84+
practices](Recommendations/R9_ModernDevelopmentPractices.md).
85+
86+
10. [Proper C/C++ interoperability](Recommendations/R10_CInteroperability.md).
87+
88+
## References
89+
90+
- [1] Fortran Community. "Fortran Best Practices". Accessed: Jun. 06, 2024.
91+
[Online] Available: https://fortran-lang.org/en/learn/best_practices/
92+
93+
- [2] Fortran Wiki Contributors. "Modernizing Old Fortran". Accessed: Jun. 06,
94+
2024. [Online] Available:
95+
https://fortranwiki.org/fortran/show/Modernizing+Old+Fortran
96+
97+
- [3] Fortran Discourse Community. "Fortran Discourse". Accessed: Jun. 06,
98+
2024. [Online] Available: https://fortran-lang.discourse.group
99+
100+
- [4] Reinhold Bader. "Fortran code modernization". Accessed: Jun. 06, 2024.
101+
[Online] Available:
102+
https://www.ugent.be/hpc/en/training/2018/modern_fortran_materials/modernfortran2018.pdf
103+
104+
- [5] The Numerical Algorithms Group. "Fortran Modernisation Workshop".
105+
Accessed: Jun. 06, 2024. [Online] Available:
106+
https://blog.rwth-aachen.de/hpc_import_20210107/attachments/39157901/39420371.pdf
107+
108+
- [6] The Carpentries. "Best Practices in Modern Fortran". Accessed: Jun. 06,
109+
2024. [Online] Available:
110+
https://wvuhpc.github.io/Modern-Fortran/11-Best-Practices/index.html
111+
112+
- [7] Norman S. Clerman, Walter Spector. "Modern Fortran: Style and Usage". 1st
113+
Edition, 2011.
114+
115+
- [8] Michael Metcalf, John Reid, Malcolm Cohen, Reinhold Bader. "Modern
116+
Fortran Explained". 6th Edition, 2023.
117+
118+
- [9] Fortran Users of NERSC (FUN). "FUN Training July 2023: Modern Fortran
119+
Basics". Accessed: Jun. 06, 2024. [Online] Available:
120+
https://www.nersc.gov/users/training/past-training-events/2023/fun-training-july-2023-modern-fortran-basics/
121+
122+
- [10] Jack Carlson, Olaf David. "Fortran 90/95 Coding Conventions - Fortran
123+
Features that are obsolescent and/or discouraged". Accessed: Jun. 06, 2024.
124+
[Online] Available:
125+
https://alm.engr.colostate.edu/cb/wiki/16983#section-Fortran+Features+that+are+obsolescent+and_2For+discouraged
126+
127+
- [11] GitHub Collaborators. "Best practices and styles guidelines of Fortran
128+
FOSS Programmers". Accessed: Jun. 06, 2024. [Online] Available:
129+
https://github.com/Fortran-FOSS-Programmers/Best_Practices
130+
131+
- [12] Fortran Discourse Community. "Our initiative to publish the
132+
'Fortran-lang Top 10 Recommendation for Fortran modernization', is it really
133+
new or even feasible?". Accessed: Jun. 06, 2024. [Online] Available:
134+
https://fortran-lang.discourse.group/t/our-initiative-to-publish-the-fortran-lang-top-10-recommendation-for-fortran-modernization-is-it-really-new-or-even-feasible/7774
135+
136+
- [13] GitHub Collaborators. "Open Catalog of Best Practices for Modernization
137+
and Optimization". Accessed: Jun. 06, 2024. [Online] Available:
138+
https://github.com/codee-com/open-catalog
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 10. Proper C/C++ interoperability
2+
3+
## Overview
4+
5+
Ensure seamless interoperability between Fortran and C/C++ to allow Fortran
6+
programs to effectively interact with a wide range of systems and libraries
7+
written in other languages (e.g., high-performance environments).
8+
9+
## Checks
10+
11+
- _Planned: Encapsulate calls to external programming models in specific
12+
procedures or modules._
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# 1. Strict compliance with modern Fortran standards
2+
3+
## Overview
4+
5+
Remove legacy features deleted from recent Fortran standards, as they might not
6+
be supported by recent compilers, and avoid compiler-specific extensions,
7+
ensuring that the code remains compatible across various development
8+
environments.
9+
10+
## Checks
11+
12+
- _Planned: Tune compiler flags to mark features removed from recent Fortran
13+
standards._
14+
15+
- _Planned: Tune compiler flags to mark compiler-specific constructs._
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 2. Declare procedures in modules
2+
3+
## Overview
4+
5+
Declare related procedures within an importable module to enhance code
6+
modularity, reusability, and readability. This practice also helps avoid
7+
runtime errors related to implicit interfaces. Separate the definition of
8+
procedures into modules and their implementation into submodules, leveraging
9+
incremental compilation to reduce build times.
10+
11+
## Checks
12+
13+
- [PWR068](https://github.com/codee-com/open-catalog/blob/main/Checks/PWR068):
14+
Encapsulate external procedures within modules to avoid the risks of calling
15+
implicit interfaces.
16+
17+
- _Planned: Consider moving the module's procedure implementations into a
18+
separate submodule._
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 3. Restrict data visibility with modules
2+
3+
## Overview
4+
5+
Encapsulate globally accessible data, such as common blocks, within modules.
6+
This approach allows for controlled access interfaces, improving code
7+
readability and minimizing side effects from global data storage.
8+
9+
## Checks
10+
11+
- [PWR073](https://github.com/codee-com/open-catalog/blob/main/Checks/PWR073):
12+
Transform common block into a module for better data encapsulation.
13+
14+
- [PWR069](https://github.com/codee-com/open-catalog/blob/main/Checks/PWR069):
15+
Use the keyword only to explicitly state what to import from a module.
16+
17+
- _Planned: Minimize mutable module variables by passing data as procedure
18+
arguments._
19+
20+
- _Planned: Privatize mutable module variables and add procedures for more
21+
controlled access._
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# 4. Improve dummy arguments semantics
2+
3+
## Overview
4+
5+
Enhance the definitions of dummy arguments to make the behavior of procedures
6+
more predictable and transparent, helping avoid common issues related to
7+
incorrect assumptions about data type, flow, or structure.
8+
9+
## Checks
10+
11+
- [PWR008](https://github.com/codee-com/open-catalog/blob/main/Checks/PWR008):
12+
Declare the intent for each procedure argument.
13+
14+
- [PWR070](https://github.com/codee-com/open-catalog/blob/main/Checks/PWR070):
15+
Declare array dummy arguments as assumed-shape arrays.
16+
17+
- _Planned: Add a contiguous attribute to applicable assumed-shape arrays._
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# 5. Improve data type consistency and management
2+
3+
## Overview
4+
5+
Ensure the consistency of data types by avoiding implicit typing and
6+
standardizing the code on a fixed set of real kinds, improving readability and
7+
portability across different development environments. Use derived data types
8+
to represent complex multi-field structures. Leverage pointers and allocatable
9+
arrays for safer memory handling.
10+
11+
## Checks
12+
13+
- [PWR007](https://github.com/codee-com/open-catalog/blob/main/Checks/PWR007):
14+
Always use implicit none to disable implicit declarations.
15+
16+
- [PWR071](https://github.com/codee-com/open-catalog/blob/main/Checks/PWR071):
17+
Prefer real(kind=kind_value) for declaring consistent floating types.
18+
19+
- _Planned: Prefer derived types over constructs such as structure or record to
20+
represent complex multi-field entities_.
21+
22+
- _Planned: Replace equivalence statements by pointers or the transfer
23+
intrinsic as needed._
24+
25+
- _Planned: Consider replacing fixed-size arrays with allocatables._
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# 6. Avoid legacy control-flow constructs
2+
3+
## Overview
4+
5+
Replace outdated and error-prone control-flow constructs with more robust and
6+
maintainable language features from recent standards, improving code
7+
maintainability and reducing the likelihood of bugs.
8+
9+
## Checks
10+
11+
- [PWR063](https://github.com/codee-com/open-catalog/blob/main/Checks/PWR063):
12+
Avoid using legacy Fortran constructs.
13+
14+
- _Planned: Use case or if-then-else constructs instead of go to statements for
15+
conditional flow._
16+
17+
- _Planned: Use do, cycle, and exit constructs instead of go to statements for
18+
loops._
19+
20+
- _Planned: Replace arithmetic if statements with block if constructs._
21+
22+
- _Planned: Convert numbered do loops to modern do loops._
23+
24+
- _Planned: End all loops with an end do statement._
25+
26+
- _Planned: Use only integer control variables in do loops._
27+
28+
- _Planned: Replace forall statements with do-concurrent constructs._
29+
30+
- _Planned: Avoid alternate return statements._
31+
32+
- _Planned: Replace compiler-dependant short-circuit logic with nested
33+
conditionals._
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 7. Enhance source code semantics
2+
3+
## Overview
4+
5+
Leverage elements from recent Fortran standards to further improve the clarity
6+
and intent of code statements beyond previous recommendations.
7+
8+
## Checks
9+
10+
- [PWR003](https://github.com/codee-com/open-catalog/blob/main/Checks/PWR003):
11+
Explicitly declare pure functions.
12+
13+
- [PWR072](https://github.com/codee-com/open-catalog/blob/main/Checks/PWR072):
14+
Add an explicit save attribute when initializing variables in their
15+
declaration.
16+
17+
- _Planned: Prefer variable initializations at declaration instead of data or
18+
block data statements._
19+
20+
- _Planned: Add an explicit parameter attribute to constant variables._
21+
22+
- _Planned: Explicitly declare elemental functions._

Recommendations/R8_CodeConventions.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 8. Adhere to code conventions
2+
3+
## Overview
4+
5+
Establish and adhere to a consistent coding standard, such as variable naming
6+
rules of free-form format, to promote readability and ease collaboration among
7+
developers.
8+
9+
## Checks
10+
11+
- _Planned: Tune compiler flags to mark fixed-form Fortran code._
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 9. Adopt modern development practices
2+
3+
## Overview
4+
5+
Integrate modern development practices, such as automated testing, version
6+
control, or dependency managers, to enhance the quality, maintainability,
7+
collaboration, and distribution of Fortran software.
8+
9+
## Checks
10+
11+
_Work in progress_

0 commit comments

Comments
 (0)