Code formatting goes beyond aesthetics, it helps development teams standardize how code is written, making it easier to read, debug, and maintain over time. In Fortran projects, especially long-lived legacy codebases, consistent formatting helps teams collaborate more efficiently and reduces cognitive load when understanding existing programs. Reading existing code is cognitively demanding, and inconsistencies slow developers down. Structured formatting helps reduce friction and makes large codebases easier to navigate.
Developers rarely share the same coding style, which makes understanding unfamiliar code more difficult. Donald Knuth’s concept of literate programming highlights that code should be written with humans in mind — focusing on clearly explaining intent rather than only instructing the machine. When code looks like it was written by one person, patterns become easier to recognize and tools such as static analysis or refactoring workflows can work more effectively.
This article is based on concepts discussed in a technical session on automated Fortran formatting.
You can watch the full webinar recording here.
Challenges of Enforcing Coding Styles
Even with well-defined coding guidelines, enforcing them manually is difficult and time-consuming. Human error inevitably introduces inconsistencies — especially in long-lived Fortran projects maintained by multiple contributors. Automated tooling helps teams keep formatting consistent while allowing developers to focus on higher-value work.
Automating Fortran Formatting with Codee
Codee provides an automated approach to formatting Fortran projects, enabling teams to:
- Automatically format free-form and fixed-form Fortran code
- Convert fixed-form code to free-form to simplify legacy maintenance
- Provide fine-grained style configuration to match existing coding conventions
- Integrate through CLI usage, Git workflows, IDEs, and CI/CD pipelines
These capabilities help teams automate formatting while keeping the codebase aligned with established coding conventions.
Applying Real-World Fortran Coding Styles
Codee Formatter’s customization capabilities are shaped by real-world Fortran development, where each project defines its own coding conventions. Rather than enforcing a single style, Codee allows teams to configure formatting rules to match existing guidelines and workflows.
The tables below illustrate how coding style rules from open-source Fortran projects — including WRF, CP2K, and FMS — map directly to Codee Formatter configuration options. These examples highlight how indentation, line length limits, whitespace handling, and end-statement formatting can be enforced through configurable properties.
Example: WRF Coding Style
| WRF Style Rule | Codee Formatter Feature |
|---|---|
| Indent code | IndentSize: Consistent indentation using a specific number of spaces |
| Do not exceed line lengths of 132 characters | ColumnLimit: Break lines longer than 132 columns |
| If modifying an existing module, follow its code style | All Codee formatting capabilities are extensively configurable |
| Use standard Fortran free format | Fixed-form to free-form conversion |
Example: CP2K Coding Style
| CP2K Style Rule | Codee Formatter Feature |
|---|---|
| Indentation with a relative width of 3 characters | IndentSize: Consistent indentation using 3 spaces |
| All operators are surrounded by exactly one whitespace character, except for arithmetic operators | SpacesAroundOperators: Customize whitespace around all language tokens as necessary |
| Removal of extraneous whitespace and consecutive blank lines | RemoveConsecutiveEmptyLines: Leave at most one empty line between code lines RemoveTrailingWhiteSpace: Remove whitespace between the last visible character and end-of-line |
| Uppercase notation for all Fortran and OpenMP keywords | Casing: Customize the casing of keywords as necessary |
| Positions of line breaks | ColumnLimit: Break lines longer than a given limit |
Example: FMS Coding Style
| FMS Style Rule | Codee Formatter Feature |
|---|---|
| Indents should be consistent. Preferred indent is 2 spaces | IndentSize: Consistent indentation using 2 spaces |
| No white space between a function name and the opening parenthesis. White space after all language token. Use space around the equal sign in variable assignment, but not when using a named optional argument | SpacesAroundOperators: Customize whitespace around all language tokens as necessary |
| No trailing white space | RemoveTrailingWhiteSpace: Remove whitespace between the last visible character and end-of-line |
| The target maximum length is 100 characters | ColumnLimit: Break lines longer than 100 columns |
do and if constructs should be terminated with the combined enddo and endif statements.All other block end statements separate the end token | EndStatementFormat: end [structure] [label] terminationEndStatementSeparation: Combine enddo and endif, and separate all other terminations |
Key Takeaways
Consistent formatting improves readability, maintainability, collaboration, and code quality. By automating coding styles and integrating into existing workflows, Codee helps development teams keep Fortran codebases consistent and easier to understand.
You can download Codee Formatter for free to start applying consistent formatting to your Fortran codebases:
Download and explore Codee Formatter →
Build correct, secure, modern and fast Fortran, C and C++ scientific software
This company is capitalized by INNVIERTE, AN INVESTMENT PROGRAM OF CDTI, E.P.E
Leave a Reply