Skip to content
perberos edited this page Nov 9, 2011 · 2 revisions

Indent style

I should like to use Allman (ANSI) style. Long line is fine too. Recommended tab width is 4, but MATE code style allow you to set any you want. 2 or 8 by example.

Type left, name right

Use pointers at the left size.

void* custom_function(char* name);
int* address = (void*) custom_function((char*) unknown_string);

Void missreading

#define SOME_TYPE_DEF (a) // replace SOME_TYPE_DEF with (a)
#define SOME_TYPE_DEF(a) // replace SOME_TYPE_DEF(a) with none

So this functions should be easy to understand

// define prototype
long int mycustom_someclass_somefunction(char a);

// define block code
long int mycustom_someclass_somefunction(char a)
{
	return (long int) some_function(a);
}

Comments

Use what ever you want.

Use tabs after each line break, and space to align code hard to read

if (declaration_is_true(some_value))
{
	static char             b; // <tab> <spaces>
	int                     a; // <tab> <spaces>
	unsigned int            some_long_value; // <tab> <spaces>
	struct my_custom_struct some_misterious_struct;

Long line is fine too

large declaration show you how much stack use a funcion, so deal with it. Next code is right.

char* omg_my_application_do_all(struct some_custom_struc* object, int* height, int* width, int* x, int* y, char* title, char* tooltip, char* description, char* sub_description, int flags)
{
	// ...

but you can use code like block on #define

#define SOME_MACRO_WITH_FUNCTION(x, y, z) \
{ \
	long dist = x * y * z; \
	if (dist <= 0) \
	{ \
		dist = 1; \
		err = DIST_IS_ZERO; \
	} \
	prev_defined = dist; \
}

Use spaces on shell scripts

Do not use tab, use 4 spaces. 2 is slightly, 8 is much. Alignment of arguments is allowed.

If you want copy paste a code and run into a shell, terminal take the tab key and will try to autocomplete some words.

Clone this wiki locally