STYLE: changes numbering scheme to transcend headers, fixes minor errors

This commit is contained in:
Emma Tebibyte 2024-09-05 15:55:32 -06:00
parent 4cb5ea78d7
commit 790b12fb40
Signed by: emma
GPG Key ID: 06FA419A1698C270

68
STYLE
View File

@ -16,13 +16,28 @@ Use
if !(argc < 0) { usage(program_name); } if !(argc < 0) { usage(program_name); }
This applies to C switch cases, as well: This applies to C switch statements and cases and Rust match statements, as
well:
switch (value) { /* aligning stuff to make it easier to read is fine */ switch (value) { /* aligning stuff to make it easier to read is fine */
case possibility: variable = foo; break; case possibility: variable = foo; break;
default: variable = NULL; break; default: variable = NULL; break;
} }
switch (value) {
case possibility:
statement;
break;
case default:
statement;
break;
}
match result {
Ok(n) => variable = n,
Err(e) => error = e,
}
1. Braces in control flow where their inclusion is left optional in C: 1. Braces in control flow where their inclusion is left optional in C:
if (condition) { statement; } if (condition) { statement; }
@ -114,24 +129,24 @@ Use
use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE }; use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE };
14. One more level of indentation for match arms and switch cases. 14. Alphabetic sorting, where applicable:
15. Alphabetic sorting, where applicable:
use std::io::{ BufWriter, Read, Write, stderr, stdin, stdout } use std::io::{ BufWriter, Read, Write, stderr, stdin, stdout }
16. In Rust, use the to_owned() method on string types (str, OsStr, CStr, etc.) 15. In Rust, use the to_owned() method on string types (str, OsStr, CStr, etc.)
and the to_string() method on other types. and the to_string() method on other types.
Avoid Avoid
===== =====
0. Heap memory allocation [0]. 16. Function pointers [0].
1. Using too much nested logic (within reason). 17. Heap memory allocation [0].
2. Too many levels of dereferences [0]: 19. Using too much nested logic (within reason).
20. Too many levels of dereferences [0]:
/* do not do this */ /* do not do this */
for (size_t i = 0; i < sizeof a / sizeof *a; ++i) { for (size_t i = 0; i < sizeof a / sizeof *a; ++i) {