STYLE: example for trailing comma & add includes guideline

This commit is contained in:
Emma Tebibyte 2024-07-15 13:29:12 -06:00
parent dc2a4a39ba
commit a0ed14a089
Signed by: emma
GPG Key ID: 06FA419A1698C270

34
STYLE
View File

@ -1,6 +1,7 @@
- Braces are mandatory for all control flow
- Nested indentation should be kept to a minimum
- Empty lines should be placed between different kinds of statements:
0. Braces are mandatory for all control flow, as it improves the visibility of
scope.
1. Nested indentation should be kept to a minimum.
2. Empty lines should be placed between different kinds of statements:
int t;
@ -20,14 +21,14 @@ io->rec += (t > 0 && io->bufuse == 0);
return io;
- Cases in switch statements and matches in match statements should be indented
3. Cases in switch statements and matches in match statements should be indented
one level
- In C, spaces should be placed in control flow statements after the keyword and
before the opening brace:
4. In C, spaces should be placed in control flow statements after the keyword
and before the opening brace:
for (i = 2; i < argc; ++i) {
- If a function, a C control flow statement, or a Rust macro has arguments that
5. If a function, a C control flow statement, or a Rust macro has arguments that
cause the statement to be broken into multiple lines, this should be done by
placing the arguments on a new line inside the parentheses:
@ -36,19 +37,30 @@ let usage = format!(
argv[0],
);
- If Rust function arguments or fields are on their own lines, they should
always have a trailing comma.
6. If Rust function arguments or fields are on their own lines, they should
always have a trailing comma:
- If text is on the same line as a brace, spaces should be placed after an
return Err(EvaluationError {
message: format!("{}: Invalid token", i),
code: EX_DATAERR,
})
7. If text is on the same line as a brace, spaces should be placed after an
opening curly brace and before a closing one:
use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE };
- If a control flow statement is short enough to be easily understood in a
8. If a control flow statement is short enough to be easily understood in a
glance, it may be placed on a single line:
if (!argc < 0) { usage(program_name); }
9. In C, note everything you use from a library in a comment subsequent to its
#include statement:
#include <unistd.h> /* close(2), getopt(3), lseek(2), read(2), write(2),
* optarg, optind, STDIN_FILENO, STDOUT_FILENO */
--
Copyright © 2024 Emma Tebibyte <emma@tebibyte.media>