Skip to content

Commit 8a1f07d

Browse files
committed
appease the linter with offerings
1 parent 663e89e commit 8a1f07d

File tree

6 files changed

+123
-111
lines changed

6 files changed

+123
-111
lines changed

components/eamxx/docs/developer/style/format.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ The summary is in the main pane of the page with the title
5252
***Actions*** link at the top of the E3SM repository page;
5353
select `eamxx-format` from the ***All workflows*** section of the ***Actions***
5454
sidebar; then choose the most recent run that is associated with your PR,
55-
which should be near the top of the list.
55+
which should be near the top of the list.
Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
11
# Functions and Methods
22

3-
### Naming
3+
## Naming
44

5-
- Please name functions (methods) to be ***descriptive*** and ***verb***_-ish_ so
5+
- Please name functions (methods) to be ***descriptive*** and ***verb**-ish* so
66
that the name describes what the function *does*.
7-
- For example, `install_flux_capacitor()` instead of `f_capacitor_method()`
8-
or `ifc()`.
9-
- To note, if your function cannot be named verb-ishly, that is probably a
10-
sign that there is a fundamental issue with your function.
7+
- For example, `install_flux_capacitor()` instead of `f_capacitor_method()`
8+
or `ifc()`.
9+
- To note, if your function cannot be named verb-ishly, that is probably a
10+
sign that there is a fundamental issue with your function.
1111
- In general, functions should use `snake_case` and not contain capitalization,
1212
unless capitalizing that quantity is a standard convention (e.g.,
1313
`find_Doc_Brown()`).
1414

15-
### Usage
15+
## Usage
1616

1717
- In situations where multiple class-member variables are passed as function
1818
arguments, favor passing the object, rather than the individual variables,
1919
for the sake of shorter lines and function signatures.
2020
- As a rule of thumb, developers should prefer passing arguments by reference,
2121
rather than by value, especially in cases for which the argument is ***large***
2222
or structurally ***complex***.
23-
- E.g., prefer `func(Type &x) { ... }` versus `func(Type x) { ... }`.
24-
- This holds true much of the time because passing by value creates a copy
25-
of the argument for use by the function, and this increases memory
26-
pressure and a resultant performance penalty.
23+
- E.g., prefer `func(Type &x) { ... }` versus `func(Type x) { ... }`.
24+
- This holds true much of the time because passing by value creates a copy
25+
of the argument for use by the function, and this increases memory
26+
pressure and a resultant performance penalty.
2727
- To be more in-depth on the topic, we echo the guidance from the
2828
[***C++ Core Guidelines***](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-introduction)
2929
and would encourage the curious to read more deeply on the topic.
3030

31-
> - For "in" parameters, pass cheaply-copied types by value and others by
32-
> reference to `const`.
33-
> - For "in-out" parameters, pass by reference to non-`const`.
34-
> - For "out" parameters, prefer return values to output parameters.
31+
> - For "in" parameters, pass cheaply-copied types by value and others by
32+
> reference to `const`.
33+
> - For "in-out" parameters, pass by reference to non-`const`.
34+
> - For "out" parameters, prefer return values to output parameters.
3535

36-
- The authors go on to explain that "cheap to copy" includes variables
37-
holding 2 or 3 words--for example a double, pointer, or reference.
38-
- To illustrate, the below function adheres to the provided guidance.
39-
40-
```c++
41-
SmallStruct func(LargeNComplex &notSmall, double forty_two, const int *laser,
42-
const BigStruct &lotsaData) {
36+
- The authors go on to explain that "cheap to copy" includes variables
37+
holding 2 or 3 words--for example a double, pointer, or reference.
38+
- To illustrate, the below function adheres to the provided guidance.
4339

44-
// SmallStruct object is only assigned-to and then returned, so it is
45-
// defined as the return type
46-
SmallStruct ans;
47-
// forty_two, a scalar double, is considered small and so passed by value
48-
ans.val = forty_two;
49-
// lotsaData, a BigStruct object, is only accessed and so is
50-
// passed by const reference
51-
ans.other_val = lotsaData.small_piece;
40+
```c++
41+
SmallStruct func(LargeNComplex &notSmall, double forty_two, const int *laser,
42+
const BigStruct &lotsaData) {
5243

53-
// we pass laser by value and as const because pointers are cheap to copy,
54-
// and the value is not changed
55-
for (int i = 0; i < forty_two; ++i) {
56-
ans.val_vector.push_back(laser[i] + notSmall.epsilon[i]);
57-
}
44+
// SmallStruct object is only assigned-to and then returned, so it is
45+
// defined as the return type
46+
SmallStruct ans;
47+
// forty_two, a scalar double, is considered small and so passed by value
48+
ans.val = forty_two;
49+
// lotsaData, a BigStruct object, is only accessed and so is
50+
// passed by const reference
51+
ans.other_val = lotsaData.small_piece;
52+
53+
// we pass laser by value and as const because pointers are cheap to copy,
54+
// and the value is not changed
55+
for (int i = 0; i < forty_two; ++i) {
56+
ans.val_vector.push_back(laser[i] + notSmall.epsilon[i]);
57+
}
5858

59-
// notSmall is large and also modified in the function, so we pass by
60-
// reference
61-
// it is also accessed, above, so it must be an argument and not the
62-
// return value
63-
notSmall.ans_struct = ans;
64-
return ans;
65-
}
66-
```
59+
// notSmall is large and also modified in the function, so we pass by
60+
// reference
61+
// it is also accessed, above, so it must be an argument and not the
62+
// return value
63+
notSmall.ans_struct = ans;
64+
return ans;
65+
}
66+
```

components/eamxx/docs/developer/style/resources/clang-format_HOWTO.md

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ Also, note that the `--style` flag can also fully define the options without
2525
the configuration file as follows, but this is not recommended as the
2626
configuration could change before this guide is updated to reflect as such.
2727

28+
<!-- markdownlint-disable MD046 MD013 -->
2829
??? Danger "Terminal One-(long-)liner"
2930

3031
```bash {.copy}
3132
clang-format [-i] --style="{BasedOnStyle: llvm, ColumnLimit: 100, AlignConsecutiveAssignments: true, AlignConsecutiveBitFields: true, AlignConsecutiveMacros: true, AlignEscapedNewlines: true, AlignTrailingComments: true}" <path/to/c++/source/file(s)>
3233
```
34+
<!-- markdownlint-enable MD046 MD013 -->
3335

3436
## Installing `clang-format`
3537

@@ -39,6 +41,7 @@ building `llvm v14` from scratch.
3941
If you are a non-admin user of a multi-user cluster, HPC platform, etc., then
4042
it is likely to be an ***easy*** process, though potentially not immediate.
4143

44+
<!-- markdownlint-disable MD046 -->
4245
??? Note "If you require or already have multiple versions of `clang-format` installed"
4346

4447
Note that, depending on your requirements, this could be placed in your shell
@@ -73,24 +76,27 @@ it is likely to be an ***easy*** process, though potentially not immediate.
7376
$ which clang-format
7477
/usr/local/bin/clang-format-14
7578
```
79+
<!-- markdownlint-enable MD046 -->
7680

7781
=== "Personal Machine"
78-
82+
83+
<!-- markdownlint-disable MD046 -->
7984
=== "Mac Users (Homebrew Package Manager)"
80-
85+
8186
For Mac users, the [Homebrew](https://brew.sh)
82-
package manager (`brew`) is the quickest and most straightforward way to get
83-
`clang-format` installed.
84-
Since `clang-format` v14 is not available to install directly from Homebrew, we
85-
install the entire LLVM package at version 14, and this is as simple as
86-
87+
package manager (`brew`) is the quickest and most straightforward way
88+
to get `clang-format` installed.
89+
Since `clang-format` v14 is not available to install directly from
90+
Homebrew, we install the entire LLVM package at version 14, and this
91+
is as simple as
92+
8793
```bash {.copy}
8894
brew install llvm@14
8995
```
90-
96+
9197
It it likely that Homebrew will issue a message about not linking the
9298
`clang`-related tools by default, so next we add the binary to our `PATH`.
93-
99+
94100
```bash {.copy}
95101
$ export PATH="/opt/homebrew/opt/llvm@14/bin/clang-format:$PATH"
96102
# Note: this is the default location for a recent Mac running Apple silicon.
@@ -99,49 +105,50 @@ it is likely to be an ***easy*** process, though potentially not immediate.
99105
$ which clang-format
100106
/opt/homebrew/opt/llvm@14/bin/clang-format
101107
```
102-
108+
103109
Note also, that if your system has multiple version of `clang-format` installed,
104110
it may be preferable to instead set a versioned alias to `clang-format`
105111
(`clang-format-14`) as in
106-
112+
107113
```c++
108114
// create a shell-alias
109115
alias clang-format-14="/opt/homebrew/opt/llvm@14/bin/clang-format"
110116
```
111-
117+
112118
=== "Linux Users (Package Manager)"
113-
119+
114120
Given the many flavors of Linux, it is difficult to generalize, but there
115121
is a high probability the proper version of `clang-format` or `llvm` is
116122
provided by the built-in package manager.
117123
The commands will differ based on your Linux distribution, but using the
118124
Debian/Ubuntu `apt` syntax, it could be accomplished via something like
119-
125+
120126
```bash {.copy}
121127
$ apt search clang-format
122128
[...]
123129
clang-format-14/...
124130
$ apt install clang-format-14
125131
```
126-
132+
127133
=== "Build from Source"
128-
129-
If you do not succeed in the above, `clang-format` can also be fully built
130-
from the [LLVM Compiler Infrastructure](https://github.com/llvm/llvm-project).
131-
It will begin with something like
132-
133-
```bash {.copy}
134-
git clone git@github.com:llvm/llvm-project.git
135-
git checkout llvmorg-14.0.6 # version tag
136-
```
137-
138-
Also, if you only need `clang-format` and not any of the other tooling,
139-
it will build faster/smaller if you use the CMake flag
140-
`-DLLVM_ENABLE_PROJECTS="clang"` to only build `clang` and it's friends,
141-
rather than all of `llvm`.
142-
And finally, the README for [LLVM version 14.0.6](https://github.com/llvm/llvm-project/tree/llvmorg-14.0.6)
143-
is far more comprehensive that the one for the latest version, and it contains
144-
instructions specific to that build.
134+
135+
If you do not succeed in the above, `clang-format` can also be fully built
136+
from the [LLVM Compiler Infrastructure](https://github.com/llvm/llvm-project).
137+
It will begin with something like
138+
139+
```bash {.copy}
140+
git clone git@github.com:llvm/llvm-project.git
141+
git checkout llvmorg-14.0.6 # version tag
142+
```
143+
144+
Also, if you only need `clang-format` and not any of the other tooling,
145+
it will build faster/smaller if you use the CMake flag
146+
`-DLLVM_ENABLE_PROJECTS="clang"` to only build `clang` and it's friends,
147+
rather than all of `llvm`.
148+
And finally, the README for [LLVM version 14.0.6](https://github.com/llvm/llvm-project/tree/llvmorg-14.0.6)
149+
is far more comprehensive that the one for the latest version, and it contains
150+
instructions specific to that build.
151+
<!-- markdownlint-enable MD046 -->
145152

146153
=== "Multi-user System"
147154

@@ -160,6 +167,7 @@ administrator to get an official version installed.[^but-conda]
160167

161168
---
162169

170+
<!-- markdownlint-disable MD046 -->
163171
??? Tip "Unnecessary but Convenient Workflow Customization (`direnv`)"
164172

165173
If you'd like to add a layer of automation/complexity to ensure you only use
@@ -170,10 +178,10 @@ administrator to get an official version installed.[^but-conda]
170178
environment variables based on `$PWD` using a `.envrc` file.
171179
As an example, here's my `.envrc` that adds `clang-format v14` to the path
172180
when I'm working on `EAMxx`.
173-
181+
174182
```bash {.copy}
175183
PATH_add /opt/homebrew/opt/llvm@14/bin/clang-format
176-
184+
177185
# also, since I often forget to load a python environment that's required for
178186
# running ctest, this creates or loads a python 3 virtual environment with numpy
179187
layout python3
@@ -182,16 +190,17 @@ administrator to get an official version installed.[^but-conda]
182190
# the front end to avoid pip endlessly reminding you to update
183191
pip install numpy
184192
```
185-
193+
186194
This file can be placed in the top-level `EAMxx` directory, and running
187195
`direnv allow` enables the functionality.
188196
Namely, executing `cd EAMxx` loads the defined environment that stays loaded
189197
in any subdirectories, and resets the standard environment when exiting to a
190198
directory above/outside of `EAMxx`.
191-
199+
192200
For the `conda` fans, this tool can also be used to auto-load a
193201
pre-configured `conda` environment since the `.envrc` is essentially a bash
194202
script with a few bells and whistles tacked on.
203+
<!-- markdownlint-enable MD046 -->
195204

196205
[^but-conda]: There are rumors of using `conda` creatively to do a user-install,
197206
but that is not an option we support or suggest.

components/eamxx/docs/developer/style/style.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,26 @@ will thank you for it!
1616
- Please give ***descriptive***, rather than ***terse***, names to your
1717
variables, functions, classes, etc.
1818
- Avoid idiosyncratic naming or styling conventions.
19-
- If the utility of a style decision would not be immediately apparent to
20-
a reasonable developer, please avoid its usage.
19+
- If the utility of a style decision would not be immediately apparent to
20+
a reasonable developer, please avoid its usage.
2121
- In the hierarchy of coding concerns, correctness and speed take the top
2222
tiers, but below that level, please favor readability and clarity over
2323
space savings, line-breaking, heavy use of arcane language features, etc.
24-
- That said, if an arcane language feature ***is*** the correct tool to
25-
be used, please do so.
26-
- And perhaps add a comment to aid the non-Jedi-Master developers who
27-
read the code next. :slightly_smiling_face:
24+
- That said, if an arcane language feature ***is*** the correct tool to
25+
be used, please do so.
26+
- And perhaps add a comment to aid the non-Jedi-Master developers who
27+
read the code next. :slightly_smiling_face:
2828
- With regard to comments, the general wisdom is that the correct amount of
2929
comments is the amount required to make the code clear and easy to understand.
30-
- To quote [Jeff Atwood](https://blog.codinghorror.com/code-tells-you-how-comments-tell-you-why/) from his essay about code comments:
30+
- To quote
31+
[Jeff Atwood](https://blog.codinghorror.com/code-tells-you-how-comments-tell-you-why/)
32+
from his essay about code comments:
3133

3234
> Only at the point where the code *cannot* be made easier to understand
3335
should you begin to add comments.
3436

35-
- However, since that does not offer much in the way of prescriptive
36-
guidance, here are some guidelines gathered from around the internet.
37+
- However, since that does not offer much in the way of prescriptive
38+
guidance, here are some guidelines gathered from around the internet.
3739
- A general rule of thumb, though not always true, is that comments
3840
should explain ***why*** something is being done in the code,
3941
rather than ***what*** the code is doing.[^butwhattabout]
@@ -49,6 +51,7 @@ parts of the code that cannot be made simpler--for instance, a clever arithmetic
4951
trick in a complicated interpolation scheme.
5052
[^dupe]: For example, this type of comment does not add any information and
5153
is unnecessary.
54+
5255
```c++
5356
// perform initialization
5457
this->initialize();

components/eamxx/docs/developer/style/style_guide_overview.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ For the purpose of this guide, we draw a distinction between these two related
55
topics and loosely define them as:
66

77
- **Style**
8-
- Style is concerned with how the code ***reads*** on a lexical level as
9-
well as with the structural and technical decisions that determine how
10-
the code ***runs***.
11-
- For example:
12-
- Descriptive, as opposed to terse, variable names.
13-
- Employing small, single-purpose functions.
14-
- Usage or non-usage of advanced C++ features.
15-
- The usage and content of comments.
8+
- Style is concerned with how the code ***reads*** on a lexical level as
9+
well as with the structural and technical decisions that determine how
10+
the code ***runs***.
11+
- For example:
12+
- Descriptive, as opposed to terse, variable names.
13+
- Employing small, single-purpose functions.
14+
- Usage or non-usage of advanced C++ features.
15+
- The usage and content of comments.
1616
- **Format**
17-
- Format is the domain of how the code ***looks*** or how the code is
18-
organized.
19-
- The good news for formatting is that we enforce a strict, LLVM-based
20-
formatting standard, and we employ
21-
[`clang-format`](https://clang.llvm.org/docs/ClangFormat.html)
22-
to automatically conduct and enforce this standard.
17+
- Format is the domain of how the code ***looks*** or how the code is
18+
organized.
19+
- The good news for formatting is that we enforce a strict, LLVM-based
20+
formatting standard, and we employ
21+
[`clang-format`](https://clang.llvm.org/docs/ClangFormat.html)
22+
to automatically conduct and enforce this standard.
2323

2424
More detail regarding each of these topics is contained in the following
2525
sections.

0 commit comments

Comments
 (0)