comply
Compliant Style Guide
Use these listings as a general guideline during development or as a reference when fixing violations.
comply is an open-source tool that helps you write better C99.
This page provides a listing of the 35 rules that comply checks your code against when running its analysis.
required advisory elective
Name | Description | Why is this important? | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
identifier-too-long |
Avoid exceeding 31 characters per identifier.
|
Identifiers should be kept as short as possible, while still retaining enough meaning that it
is immediately clear what it represents- or does.
|
||||||||||||||||||
line-too-long |
Don't exceed 80 characters per line.
|
Any line of code should fit on the screen it is being viewed on under any scenario;
whether single file or side-by-side.
Lines shorter than 80 characters will fit on most viewers, thus improving readability. References:
|
||||||||||||||||||
func-too-long |
Avoid exceeding 40 lines per function.
|
A large function can be difficult to read and easily comprehend- especially so if it requires
scrolling to fully fit on the screen/display of the viewer.
Additionally, and similar to too-many-params, when a function is getting large and increasingly complex, it is also often a sign that it is doing too much and would likely benefit from being refactored into smaller parts. References:
|
||||||||||||||||||
invisible-characters |
Don't put invisible characters in code.
|
Invisible characters (in code, i.e. not in literals) serve no useful purpose and may confuse both editing tools and readers. |
||||||||||||||||||
duplicate-include |
Don't include another file more than once (per file).
|
|||||||||||||||||||
unnamed-int |
Provide meaningful names for integer parameters if able.
|
The majority of function prototypes will suffer from having unnamed integer parameters,
as their meaning might be difficult to derive without.
|
||||||||||||||||||
symbol-used |
Always list used symbols as needed/required.
|
If your code is using a symbol, but not explicitly telling where it got it from, you might have
a hard time figuring out just how far your code reaches out.
|
||||||||||||||||||
too-many-params |
Don't exceed 4 parameters per function.
|
When a function has many parameters, it is often a sign that it is doing too much and would benefit from being refactored into smaller parts. Each parameter adds to the complexity of a function, and the more it has, the harder it becomes
to understand (and use).
References:
|
||||||||||||||||||
redundant-const |
Don't mark parameter names as
|
A function parameter name might be marked as |
||||||||||||||||||
pad-braces |
Always pad braced bodies with inner whitespace.
|
|||||||||||||||||||
missing-braces |
Always surround the bodies of control statements with scoped braces.
|
You might be tempted to save a line or two by not adding braces to that single-line References:
|
||||||||||||||||||
inconsistent-name-placement |
Always place function name and return type on separate lines (for function implementations).
|
This style provides a quick and consistent reading of functions, and helps in reducing line length when return types are long and complicated. References:
|
||||||||||||||||||
too-many-blanks |
Don't add more than 1 blank line, neither leading, nor following, any line of code.
|
Blank lines are occasionally used as a way of partitioning or grouping chunks of logically separated code, but this is not recommended. |
||||||||||||||||||
pad-commas |
Always follow comma-separators by whitespace.
|
|||||||||||||||||||
prefer-stdint |
Always use explicitly sized integer types (e.g.
Read moreHere's a general table of reference:
|
Being explicit about the type and size that you want to use helps improve portability.
It's worth noting that when sticking with basic types (e.g. References:
|
||||||||||||||||||
file-too-long |
Avoid exceeding 600 lines per source file.
|
Files that are very long can be difficult to navigate and easily comprehend, and may indicate that the file is too extensive and covering too many things. Note that, as with func-too-long, this limit is completely arbitrary and only serves as a general indicator of complexity. Whether or not a file is actually too long is highly variable and can only be judged on a situational basis. |
||||||||||||||||||
redundant-size |
Don't specify array length in function signatures unless it can be enforced.
|
The size specification for pointer-degrading array parameters is not enforced by the compiler,
thus making it a source of confusion that should be avoided.
References:
|
||||||||||||||||||
unified-header |
Don't use unified headers if you can avoid it.
|
A unified header is a header file whose only purpose is to include other header files. As convenient as they may be, unified headers do not promote modularity and increases compile time in cases where the consumer does not need all of the included headers. References:
|
||||||||||||||||||
paramless-func |
Always specify parameters as
|
Technically, this is not required for the compiler to do its job, but being explicit helps in keeping a clear and consistent interface. |
||||||||||||||||||
require-symbols |
Always list needed/required symbols.
|
Helps in determining dependencies that are no longer needed and could be removed,
and encourages use of smaller, more well-defined headers.
By maintaining these lists obsessively you make it much easier for yourself, and others, to determine the actual dependencies of your code. References:
|
||||||||||||||||||
pad-keywords |
Always pad control keywords (
|
Padding control keywords improves readability by clearly separating them from macros and function calls. |
||||||||||||||||||
tab-characters |
Don't use tabs. Use spaces.
|
Using tabs for indentation will produce inconsistent line lengths, as the size of a tab may vary depending on the viewer. References:
|
||||||||||||||||||
unused-symbol |
Don't list unused symbols as needed.
|
Helps in determining when a symbol is no longer used, potentially leading to being able to
remove an inclusion completely, reducing dependencies and improving maintainability.
|
||||||||||||||||||
filename-has-whitespace |
Avoid whitespace in filenames.
|
Mostly a matter of convention, but helps in avoiding issues when interacting with the file on the command-line or through external tools. |
||||||||||||||||||
left-aligned-const |
Always place
|
Placing References:
|
||||||||||||||||||
guard-header |
Always provide include guards in header files.
|
Helps prevent redundant inclusions and improves compilation times. |
||||||||||||||||||
logical-continuation |
Don't begin lines with a logical continuation.
|
|||||||||||||||||||
pad-pointers |
Always pad pointer declarations with space on both sides.
|
Having no padding for References:
|
||||||||||||||||||
including-source |
Don't include source files (.c) in other source files.
|
This is advisable to avoid potentially compiling the same unit twice, resulting in multiple symbol definitions and linker errors. |
||||||||||||||||||
header-in-header |
Don't include other headers if you can avoid it.
|
Avoiding header inclusions can help keep compile times low. Forcing source files to include everything they need helps provide a clear picture on the dependencies of the particular unit and makes it easier to spot redundancies. References:
|
||||||||||||||||||
todo |
Use
|
These small notes are great for quickly persisting thoughts directly related to specific parts of your code. They serve as reminders for both yourself, and others, that something needs to be looked at eventually. However, it is dangerous todo-and-forget; in time, these reminders may turn stale-
the context might be forgotten, or the issue silently fixed- yet the |
||||||||||||||||||
redundant-name |
Don't name parameters identically to their type.
|
Redundant information is never useful. If a parameter can not be named something meaningful, then it is typically better omitted. References:
|
||||||||||||||||||
padded-parens |
Don't pad parenthesized groups with whitespace.
|
|||||||||||||||||||
ambiguous-func |
Don't provide ambiguous function declarations.
|
This mainly pertains to functions with parameterless declarations.
|
||||||||||||||||||
scope-too-deep |
Don't write deeply nested code.
|
A deeply nested scope is often an indication of too high complexity and can be difficult to read. |