This commit is contained in:
Miloslav Ciz 2021-08-24 20:15:56 -05:00
parent 680024916a
commit f2b9cc23f5
1 changed files with 31 additions and 9 deletions

View File

@ -5,6 +5,19 @@ This is my C99 formatting style guide.
GENERAL
-------
- Use empty spaces to nicely separate chunks of code that belongs together,
e.g.:
int a = x;
char b = y;
if (a > b)
doSomething();
if (something())
doSomethingElse();
- Undef macros when no longer needed. This prevents clashes.
INDENTATION
-----------
@ -21,7 +34,8 @@ INDENTATION
tabs are on, editor does shit like automatically replace spaces with tabs,
you don't want your editor to be smart and fuck up your code behind your
back. Tabs force bloat in text editors. Tabs just bother people who don't
use them and don't have them configured.
use them and don't have them configured, this isn't he case the other way
around (there isn't anyone who doesn't have spaces configured).
IDENTIFIERS
-----------
@ -41,6 +55,18 @@ IDENTIFIERS
MyInt
SceneArray
In code that is meant to be reused elsewhere use a namespace prefix for glabal
identifiers, typically formed by three uppercase letters (usually an
abbreviation of project's name) followed by an underscore, e.g. for My Awesome
Project a global identifier "var" would be:
MAP_var
Prefix private/internal global variables with underscore to avoid clashes with
normal identifiers, e.g.:
_MAP_privateVar
CURLY BRACKETS
--------------
Write curly brackets like this:
@ -52,14 +78,13 @@ CURLY BRACKETS
}
Reasons:
-
- Visually very well readable.
- Visually very well readable, same level brackets are aligned. The lines
with brackets also create nice empty spaces separating chunks of code.
- Results in more LOC, forcing the programmer a little more to write shorter
code.
If there is a single command in the block, don't write curly brackets.
If not required (a single command in block), don't use brackets, except with
tricky structures (e.g. if-else inside an if).
LINE LENGTH
-----------
@ -93,6 +118,3 @@ COMMENTS
license).
Use Doxygen style comments so that auto doc can easily be created.