How I program C
In order to maintain high-quality, readable, and maintainable code across our projects, we have established a set of guidelines.
Variables
Naming conventions:
- Global Constant:
GLOBAL_CONST
- Global Variables:
Global_Ver
- Struct Variable:
struct_var
- Struct Variable:
- Local Variables:
local_var
- Global Constant:
Marco function:
macroFunc
Functions
- Naming convention:
my_functions
- Don't do early return.
Use K&R Styles in functions:
.cfn int my_func() { // something return int; }
Other
- Sturct:
MyStruct
- Types:
IntType
Loops:
Use
i
when indexing in loop.cfor (int i = 0; i < 10; i++) { }
Switch Case
Add scope in cases and breaks inside them:
.cswitch(condition) { case match1: { // something break; } default: { // something } }
Reusable Names:
- Global:
len
: Lengthcount
,size
root
: root nodenode
: links to other nodesnext
: next nodeimg
: imagetype
: enum
- Variables:
bg
&fg
: background & foreground.src
&dest
: source & destinationres
&req
: response & requestx
&y
: x & y coordinatesheight
&width
theme
font
state
ptr
: pointermsg
: message- File System:
file
: file pointerfilename
filepath
path
: for both file & directory pathdirpath
- Functions:
get
&set
: getting and setting data trough.to
: convert to one source to other. (eg: to_vec3_rgb)alloc
&free
: allocate and freeing the memorymake
,remove
,update
print
: showing the message in terminalhandle
: Pointer opaque data in function.init
: initialization
- Log:
- Level: Log levels
debug
info
warn
: warningerr
: error
- Level: Log levels