style/README.md
2025-01-14 13:21:50 -05:00

930 B

Style Guide

This document lays out my general style guide when writing code, mostly in C.

General Opinions

  • Lines should try to be at most 80 columns.
  • Four (4) spaces in a tab. No tab characters.
  • THE POINTER GOES ON THE LEFT.
  • Single line (//) comments for comments on the code. Multi-line (/**/) for other things, e.g. examples, algorithm explanations, narratives, &c.

Line Breaks

In general, keep things on as few lines as possible / legible. Obviously, this means function declarations should be on one line if possible. Keep as best as possible to an 80-column limit.

Examples:

looooooooooooooooooong type
llllllllllong_function_name(with a, lot of, arguments* h) {
    return something;
}
// Skip all whitespace.
while (*inp == ' ' || *inp == '\t') inp++;

Comment Style

In comments, use markdown.

// Print `var`.
void print(char* var) {
    printf("%s\n", var);
}