Skip to content

Code Guidelines

Felix Kaaman edited this page Jun 25, 2016 · 1 revision

Iceball is written in both C and Lua, and contributions using either should follow these guidelines. Existing code that does not follow these guidelines should not be re-formatted if the contribution isn't specifically for converting it.

Lua

TODO

C

Newlines

Functions should have the curly brace on a newline, otherwise they should be on the same line

// good
void foo()
{

}

// bad
void bar() {
}

// good
if (a) {
	foo();
}

// bad
if (a)
{
	foo();
}

Whitespace

Use hard tabs for both indenting and alignment.

// good
void foo()
{
	printf("foo");
}

// bad
void foo()
{
  printf("foo");
}

Don't rely on any tab size when aligning

// good
foobar(
	a,
	b,
	c
);

// good
foobar(
	a,
	b,
	c);
}

// bad
foobar(a,
	   b,
	   c);

Generally, operators should have some padding.

// good
int a = (b * c) / 10;

// bad
int a = (b*c)/10;

// good
for (int i = 0; i < 10; ++i)
	printf("%d\n", i);

// bad
for (int i=0; i<10; ++i)
	printf("%d\n", i);

if and for should have a separating space between the parenthesis.

// good
if (a)
	foo();

// bad
if(a)
	foo();

// good
for (int i = 0; i < 10; ++i)
	printf("%d\n", i);

// bad
for(int i = 0; i < 10; ++i)
	printf("%d\n", i);

Function calls should not have a separating space or padding inside the parenthesis.

// good
foo(a, b, c);

// bad
foo (a, b, c)

// bad
foo( a, b, c )

Globals

TODO

Clone this wiki locally