STYLE: extern and use statements rules
This commit is contained in:
parent
9f2447ce94
commit
3ba6682ab3
31
STYLE
31
STYLE
@ -1,6 +1,8 @@
|
|||||||
0. Braces are mandatory for all control flow, as it improves the visibility of
|
0. Braces are mandatory for all control flow, as it improves the visibility of
|
||||||
scope.
|
scope.
|
||||||
|
|
||||||
1. Nested indentation should be kept to a minimum.
|
1. Nested indentation should be kept to a minimum.
|
||||||
|
|
||||||
2. Empty lines should be placed between different kinds of statements:
|
2. Empty lines should be placed between different kinds of statements:
|
||||||
|
|
||||||
int t;
|
int t;
|
||||||
@ -22,7 +24,7 @@
|
|||||||
return io;
|
return io;
|
||||||
|
|
||||||
3. Each block of code should be indented once more than the keyword which
|
3. Each block of code should be indented once more than the keyword which
|
||||||
initiated the block:
|
initiated the block:
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'e': mode |= EQUAL; break;
|
case 'e': mode |= EQUAL; break;
|
||||||
@ -32,13 +34,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
4. In C, spaces should be placed in control flow statements after the keyword
|
4. In C, spaces should be placed in control flow statements after the keyword
|
||||||
and before the opening brace:
|
and before the opening brace:
|
||||||
|
|
||||||
for (i = 2; i < argc; ++i) {
|
for (i = 2; i < argc; ++i) {
|
||||||
|
|
||||||
5. 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
|
cause the statement to be broken into multiple lines, this should be done by
|
||||||
placing the arguments on a new line inside the parentheses:
|
placing the arguments on a new line inside the parentheses:
|
||||||
|
|
||||||
let usage = format!(
|
let usage = format!(
|
||||||
"Usage: {} [-d delimiter] index command [args...]",
|
"Usage: {} [-d delimiter] index command [args...]",
|
||||||
@ -46,7 +48,7 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
6. If Rust function arguments or fields are on their own lines, they should
|
6. If Rust function arguments or fields are on their own lines, they should
|
||||||
always have a trailing comma:
|
always have a trailing comma:
|
||||||
|
|
||||||
return Err(EvaluationError {
|
return Err(EvaluationError {
|
||||||
message: format!("{}: Invalid token", i),
|
message: format!("{}: Invalid token", i),
|
||||||
@ -54,21 +56,32 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
7. If text is on the same line as a brace, spaces should be placed after an
|
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:
|
opening curly brace and before a closing one:
|
||||||
|
|
||||||
use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE };
|
use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE };
|
||||||
|
|
||||||
8. 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:
|
glance, it may be placed on a single line:
|
||||||
|
|
||||||
if (!argc < 0) { usage(program_name); }
|
if (!argc < 0) { usage(program_name); }
|
||||||
|
|
||||||
9. In C, note everything you use from a library in a comment subsequent to its
|
9. In C, note everything you use from a library in a comment subsequent to its
|
||||||
#include statement:
|
#include statement:
|
||||||
|
|
||||||
#include <unistd.h> /* close(2), getopt(3), lseek(2), read(2), write(2),
|
#include <unistd.h> /* close(2), getopt(3), lseek(2), read(2), write(2),
|
||||||
* optarg, optind, STDIN_FILENO, STDOUT_FILENO */
|
* optarg, optind, STDIN_FILENO, STDOUT_FILENO */
|
||||||
|
|
||||||
|
10. In Rust, place extern statements after use statements that include standard
|
||||||
|
library crates. Group alike statements:
|
||||||
|
|
||||||
|
use std::fs::Path;
|
||||||
|
|
||||||
|
extern crate strerror;
|
||||||
|
extern crate sysexits;
|
||||||
|
|
||||||
|
use strerror::StrError;
|
||||||
|
use sysexits::{ EX_OSERR, EX_USAGE };
|
||||||
|
|
||||||
--
|
--
|
||||||
Copyright © 2024 Emma Tebibyte <emma@tebibyte.media>
|
Copyright © 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user