Common Look - Spacing and Tabulations

Tabulators are optional. 1 tabulation shall equal 4 space characters.

Long lines

It is advised to set a limit on how long a line can be. Recommended value is about 100 characters. Lines which exceed this limit should be formatted in the following way:

Step1: After the first opening round brace a newline shall be placed. Next newline shall be placed before the matchin closing brace.

Contents in the braces shall be indented from the line it continues.

Closing brace shall be indented by 1 tab.

Before:

void long_function_name( long_parameter_type const & _parameter );

After:

void long_function_name(
		long_parameter_type const & _parameter
);

If a line has multiple elements separated by commas ( or possibly other operators ) then these elements shall be listed one per line with comma leading.

Before:

void long_function_name( long_parameter_type const & _parameter1
, long_parameter_type const & _parameter2, long_parameter_type const & _parameter3 );

After:

void long_function_name(
		long_parameter_name const & _parameter1
	,	long_parameter_name const & _parameter2
	,	long_parameter_name const & _parameter3
	);

Once this rule needs to be used, it shall be used recursively for all elements ( example – in function calls ). Recursivity may be not used if something inside brackets is trivially short to write ( such case is bolded on the example below );

before:

function1( parameter1, function2( parameter2, 20, function3( paremeter1 ) ), parameter3 );

after:

function1(
		parameter1
	,	function2(
				parameter2
			,	20
			,	function3( paremeter1 ) 
			)
	,	parameter3
	);

step2: if applying the step1 did not shorten the line to not breach maximum length then the line shall be split in the same manner with regards to angle brackets.

(std::vector< std::map< std::string, std::pair< int, std::pair< std::set<
size_t > > > > > function( parameter _parameter, std::set< std::string > );

after:

std::vector<
		std::map<
				std::string
			,	std::pair<
						int
					,	std::pair<
								std::set< size_t >
							>
					>
			>
	> function(
			parameter _parameter
		,	std::set< std::string > _set
	);

Step3: if a line is long due to a chain of dereferences then split them in the following way:

before:

object1->object2.object3.object4->object5->function( parameter )->function(
parameter2->function66()->function55() ).function();

after:

	object1
->	object2
.	object3
.	object4
->	object5
->	function( parameter )
->	function(
			parameter2
		->	function66()
		->	function55()
		)
.	function()
;