Open HunterZ opened 2 years ago
Formatting and style guide:
Basic text formatting:
Basic code formatting:
/*
...*/
comment styleFlow control formatting/structure:
while
/if
/etc. if they contain multiple lines of indented code under them (original codebase would nest a loop inside another loop, and not use braces under the outer loop - no!)while
/if
/etc. contains only one line, prefer putting them on the same line if they'll fit togetherelse
following a multi-line if
and vice versa, etc.if
...else
, to avoid the else
being a double-negativeelse
blocks around code that follows an if
block ending in a break
/continue
/return
statementbreak
/continue
/return
where possible to avoid unnecessary else
blocksgoto
is long out of vogue, so try to avoid/eliminate itLoop/increment/decrement semantics:
++i
) to post-increment/decrement (i--
)Pointer/array semantics:
Code structure:
if
sVariables/types:
*
goes next to the variable name, not the type (exception: *const
because there's no alternative)Functions:
(void)
to swallow return values - it makes the code overly verboseconst
arguments where possibleMacros:
#ifdef
to #if defined()
when checking a single macro condition#if
...#elif
...#else
...#endif
to nesting when possibleRegarding ANSI C:
access()
for now, but it's pretty compatible and simple on Windows.
There's a bunch of dead code in the codebase:
#ifdef
'd out stuffAlso need to get down to one common implementation that supports Windows, Mac, and Linux, with no/minimal macrobatics. This means leaning on BearLibTerminal for I/O as much as possible, and trying to stick to ANSI C as much as possible for everything else (file I/O etc.).