Fossil source code should following the style guidelines below.
General points::
- No line of code exceeds 80 characters in length. (Occasional exceptions are made for HTML text on @-lines.)
- There are no tab characters.
- Line terminators are \n only. Do not use a \r\n line terminator.
- 2-space indentation is used. Remember: No tabs.
- Comments contain no spelling or grammatical errors. (Abbreviations and sentence fragments are acceptable when trying to fit a comment on a single line as long as the meaning is clear.)
- The tone of comments is professional and courteous. Comments contain no profanity, obscenity, or innuendo.
- All C-code conforms to ANSI C-89.
- All comments and identifiers are in English.
- The program is single-threaded. Do not use threads. (One exception to this is the HTTP server implementation for Windows, which we do not know how to implement without the use of threads.)
C preprocessor macros:
- The purpose of every preprocessor macros is clearly explained in a comment associated with its definition.
- Every preprocessor macro is used at least once.
- The names of preprocessor macros clearly reflect their use.
- Assumptions about the relative values of related macros are verified by asserts. Example: assert(READ_LOCK+1==WRITE_LOCK);
Function header comments:
- Every function has a header comment describing the purpose and use of the function.
- Function header comment defines the behavior of the function in sufficient detail to allow the function to be re-implemented from scratch without reference to the original code.
- Functions that perform dynamic memory allocation (either directly or indirectly via subfunctions) say so in their header comments.
Function bodies:
- The name of a function clearly reflects its purpose.
- Automatic variables are small, not large objects or arrays. Avoid excessive stack usage.
- The check-list items for functions also apply to major subsections within a function.
- All code subblocks are enclosed in {...}.
- assert() macros are used as follows :
- Function preconditions are clearly stated and verified by asserts.
- Invariants are identified by asserts.
Class (struct) declarations:
- The purpose and use of every class (a.k.a. structure) is clearly defined in the header comment of its declaration.
- The purpose and use of every class member is clearly defined either in the header comment of the class declaration or when the member is declared or both.
- The names of class members clearly reflect their use.
- Invariants for classes are clearly defined.
Variables and class instances:
- The purpose and use of every variable is defined by a comment at the variable definition.
- The names of variables clearly reflect their use.
- Related variables have related names. (ex: aSavepoint and nSavepoint.)
- Variables have minimum practical scope.
- Automatic variables are small, not large objects or arrays.
- Constants are "const".
- Invariants on variables or groups of variables are defined and tested by asserts.
- When a variable that refers to the same value is used within multiple scopes, the same name is used in all cases.
- When variables refer to different values, different names are used even when the names are in different scopes.
- Variable names with wide scope are sufficiently distinctive to allow searching for them using grep.