-
Notifications
You must be signed in to change notification settings - Fork 326
CS Coding Style Guidelines
Brian "Beej Jorgensen" Hall edited this page Dec 18, 2018
·
3 revisions
Though individual programs might have their own guidelines, these are the style guidelines for the CS portion of the curriculum.
Be compliant with PEP 8.
- Autopep8: tool to reformat code.
- autoflake: removes unused variables and imports.
- VS Code linting: can get the job done in VS Code.
We'll use a variant of K&R style.
- Function braces on the next line after the function definition.
- Flow control braces on the same line as the flow control statement.
- 4 spaces for an indent.
- Spaces around operators for clarity.
- Just a space after a
;
or,
.
- Just a space after a
- Asterisk next to the variable name in pointer declarations.
#include <stdio.h>
int mul2(int x)
{
return x * 2;
}
int main(void)
{
int i, j;
char *p, *q;
for (i = 0; i < 20; i++) {
if (i > 10) {
printf("Hi!\n");
} else {
printf("Hello!\n");
}
}
return 0;
}