57 lines
1.7 KiB
Plaintext
57 lines
1.7 KiB
Plaintext
|
- Braces are mandatory for all control flow
|
||
|
- Indentation should be kept to a minimum
|
||
|
- Empty lines should be placed between different kinds of statements:
|
||
|
|
||
|
int t;
|
||
|
|
||
|
assert(io->bufuse > 0);
|
||
|
assert(io->bufuse <= io->bs);
|
||
|
|
||
|
if ((t = write(io->fd, io->buf, io->bufuse)) < 0) {
|
||
|
io->error = errno;
|
||
|
t = 0;
|
||
|
} else if (t > 0) {
|
||
|
memmove(io->buf, &(io->buf)[t], (io->bufuse -= t));
|
||
|
}
|
||
|
|
||
|
io->bytes += t;
|
||
|
io->prec += (t > 0 && io->bufuse > 0);
|
||
|
io->rec += (t > 0 && io->bufuse == 0);
|
||
|
|
||
|
return io;
|
||
|
|
||
|
- 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:
|
||
|
|
||
|
for (i = 2; i < argc; ++i) {
|
||
|
|
||
|
- 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:
|
||
|
|
||
|
let usage = format!(
|
||
|
"Usage: {} [-d delimiter] index command [args...]",
|
||
|
argv[0],
|
||
|
);
|
||
|
|
||
|
- 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
|
||
|
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
|
||
|
glance, it may be placed on a single line:
|
||
|
|
||
|
if (!argc < 0) { usage(program_name); }if (!(argc < 0)) { usage(program_name); }
|
||
|
|
||
|
--
|
||
|
Copyright © 2024 Emma Tebibyte <emma@tebibyte.media>
|
||
|
|
||
|
This work is licensed under CC BY-SA 4.0. To view a copy of this license, visit
|
||
|
<http://creativecommons.org/licenses/by-sa/4.0/>.
|