You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/sphinx/source/libCEEDdev.md
+58Lines changed: 58 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -201,8 +201,66 @@ In addition to those automatically enforced style rules, libCEED tends to follow
201
201
- Type names: `PascalCase` or language specific style
202
202
- Constant names: `CAPS_SNAKE_CASE` or language specific style
203
203
204
+
In general, variable and function names should avoid abbreviations and err on the side of verbosity to improve readability.
205
+
204
206
Also, documentation files should have one sentence per line to help make git diffs clearer and less disruptive.
205
207
208
+
## Function Conventions
209
+
210
+
### Naming
211
+
All functions in the libCEED library should be prefixed by `Ceed` and generally take a `Ceed` object as its first argument.
212
+
If a function takes, for example, a `CeedOperator` as its first argument, then it should be prefixed with `CeedOperator`.
213
+
214
+
### Style
215
+
Functions should adhere mostly to the PETSc function style, specifically:
216
+
217
+
1. All local variables of a particular type (for example, `CeedInt`) should be listed on the same line if possible; otherwise, they should be listed on adjacent lines. For example,
218
+
```c
219
+
// Correct
220
+
CeedInt a, b, c;
221
+
CeedInt *d, *e;
222
+
CeedInt **f;
223
+
224
+
// Incorrect
225
+
CeedInt a, b, c, *d, *e, **f;
226
+
```
227
+
228
+
2. Local variables should be initialized in their declaration when possible.
229
+
3. Nearly all functions should have a return type of `int` and return a `CeedErrorType` to allow for error checking.
230
+
4. All functions must start with a single blank line after the local variable declarations.
231
+
5. All libCEED function calls must have their return value checked for errors using the `CeedCall()` or `CeedCallBackend()` macro.
232
+
This should be wrapped around the function in question.
233
+
6. In libCEED functions, variables must be declared at the beginning of the code block (C90 style), never mixed in with code.
234
+
However, when variables are only used in a limited scope, it is encouraged to declare them in that scope.
235
+
7. Do not put a blank line immediately blank line immediately before `return CEED_ERROR_SUCCESS;`.
236
+
8. All libCEED functions must use Doxygen comment blocks before their *definition* (not declaration).
237
+
The block should begin with `/**` and end with `**/`, each on their own line.
238
+
The block should be indented by two spaces and should contain an `@brief` tag and description, a newline, a line stating whether the function is collective, a newline, `@param` tags for each parameter, a newline, and a `@return` line formatted exactly as in the example below.
239
+
All parameter lines in the Doxygen block should be formatted such that parameter names and descriptions are aligned.
240
+
There should be a exactly one space between `@param[dir]` (where `dir` is `in`, `out`, or `in,out`) and the parameter name for the closest pair, as well as between the parameter name and description.
241
+
For example:
242
+
```c
243
+
/**
244
+
@brief Initialize a `Ceed` context to use the specified resource.
245
+
246
+
Note: Prefixing the resource with "help:" (e.g. "help:/cpu/self") will result in @ref CeedInt() printing the current libCEED version number and a list of current available backend resources to `stderr`.
247
+
248
+
@param[in] resource Resource to use, e.g., "/cpu/self"
249
+
@param[out] ceed The library context
250
+
251
+
@return An error code: 0 - success, otherwise - failure
252
+
253
+
@ref User
254
+
255
+
@sa CeedRegister() CeedDestroy()
256
+
**/
257
+
intCeedInit(const char *resource, Ceed *ceed) {
258
+
```
259
+
9. Function declarations should include parameter names, which must exactly match those in the function definition.
260
+
10. External functions, i.e. those used in tests or examples, must have their *declarations* prefixed with `CEED_EXTERN`.
261
+
All other functions should have their *declarations* prefixed with `CEED_INTERN`.
262
+
Function *definitions* should have neither.
263
+
206
264
## Clang-tidy
207
265
208
266
Please check your code for common issues by running
0 commit comments