Skip to content

Commit f72beb1

Browse files
committed
doc: style guide based on comments in #3
1 parent d1dcc8b commit f72beb1

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

.editorconfig

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ root = true
1010

1111
[*.{f90,F90}]
1212
indent_style = space
13-
indent_size = 2
13+
indent_size = 4
1414
trim_trailing_whitespace = true
1515
max_line_length = 132
1616
insert_final_newline = true
1717

1818
[{CMakeLists.txt, *.cmake}]
1919
indent_style = space
20-
indent_size = 2
20+
indent_size = 4
2121
trim_trailing_whitespace = true
2222
max_line_length = 132
2323
insert_final_newline = true
@@ -38,7 +38,7 @@ insert_final_newline = true
3838

3939
[*.sh]
4040
indent_style = space
41-
indent_size = 2
41+
indent_size = 4
4242
trim_trailing_whitespace = true
4343
max_line_length = 132
4444
insert_final_newline = true

STYLE_GUIDE.md

+64-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,66 @@
11
# Fortran stdlib Style Guide
22

3-
This document will describe the code style to use.
3+
> [A]utomate and codify as much as you possibly can while remembering that the human touch is still necessary to praise
4+
> and be kind to your contributors.
5+
> Let robots handle your project’s pedantry and humans handle your project’s empathy.
6+
7+
-- @mikemcquaid, [Homebrew] project leader<sup>[1]</sup>
8+
9+
[1]: https://mikemcquaid.com/2018/06/05/robot-pedantry-human-empathy/
10+
[Homebrew]: https://brew.sh
11+
12+
## File naming conventions
13+
14+
- Source files should contain at most one `program`, `module`, or `submodule`.
15+
- The filename should match the program or module name and have the file extension `.f90` or `.F90` if preprocessing is required.
16+
- If the interface and implementation is split using submodules the implementation submodule file should have the same name as the interface (parent) module but end in `_implementation`. E.g., `string_class.f90` and `string_class_implementation.f90`
17+
- Tests should be added in the `tests` subdirectory and have the same name as the module they are testing with the `test_` prefix added. E.g., `string_class.f90` and `tests/test_string_class.f90`
18+
19+
## Indentation & whitespace
20+
21+
By setting and following a convention for indentation and whitespace, code reviews and git-diffs can
22+
focus on the semantics of the proposed changes rather than style and formatting.
23+
24+
* __TABs vs spaces__: __Spaces__: TABs should never be used for indentation
25+
* __Trailing whitespace__: All trailing whitespace must be removed
26+
* __End of File (EOF)__: The file must end in a single new-line character
27+
* __Line length__: __132__: The Fortran 90 (and later) standard mandates lines be no longer than 132 characters
28+
* __Indentation__: __Four (4) spaces__ for all control constructs, line continuations, etc.
29+
* __Line ending character__: __Native__: Git will convert line endings to `\n` (Unix style) on commit, and will checkout files with native line endings
30+
31+
## Variable and procedure naming
32+
33+
Variable names should be descriptive, and not artificially short.
34+
By default, where it makes sense to do so, variable names shall be made up of one or more full words separated by an underscore.
35+
For cases where a conventional & appropriate shortening of a word is used then the underscore may be omitted.
36+
37+
Examples:
38+
39+
__GOOD__:
40+
41+
``` fortran
42+
logical :: has_failed
43+
real function linspace(...)
44+
```
45+
46+
__BAD__:
47+
48+
``` fortran
49+
logical :: has_failed
50+
real function lin_space(...)
51+
```
52+
53+
## Keyword case
54+
55+
Fortran keywords should __*not*__ be UPPERCASE.
56+
Modern editors and IDEs can highlight Fortran syntax and UPPERCASE keywords.
57+
UPPERCASE keywords give Fortran source code the appearance of being antiquated.
58+
59+
## End <scope> block closing statements
60+
61+
Fortran allows certain block constructs or scopes to include the name of the program unit in the end statement.
62+
The convention adopted herein is to __NOT__ include procedure names, `module` names and `program` names in the `end` statement.
63+
There should only ever be one `program` and `module` statement per file and therefore including the name provides no useful information.
64+
An exception to this rule is for procedures (`function`s and `subroutine`s) that are longer than a page of text.
65+
Long procedures often are a sign of poor abstraction, however, sometimes they are necessary.
66+
In such cases, the procedure name may be included in the `end` procedure statement.

0 commit comments

Comments
 (0)