Coding Style: indenting with tabs vs. spaces

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Benny Halevy
Date: Thursday, November 8, 2007 - 3:36 am

Greetings,

I would like to hear peoples opinion about the indentation convention
described below that I personally found the most practical with
several different editors.

The gist of it is that tabs should be used for nesting, not for decoration.
Indent your code with as many tabs as your nesting level, where all statements
will begin, and from there on use space characters.
The rational behind it is to be tab-width agnostic so regardless of your
tab expansion setup, the code will look correct and will make sense.

When you break a line and want the new line text to start below a specific point
relative to the previous line (I consider that "decorating") then start the new
line with the same number of tabs as the previous one and then just use space
characters as their width is the same as any character in the previous line,
(assuming fixed-width fonts of course).

For example:

{
	if (very_long_expression &&
	    it_needs_to_be_broken_into_several_lines)
		return a_very_long_result +
		       the_remainder_of_it_that_spilled_off +
		       to_the_next_lines;

	return printk("just my %d cents\n",
	              2);
}

Thanks,

Benny

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Coding Style: indenting with tabs vs. spaces, Benny Halevy, (Thu Nov 8, 3:36 am)
Re: Coding Style: indenting with tabs vs. spaces, Chris Snook, (Thu Nov 8, 8:58 am)
Re: Coding Style: indenting with tabs vs. spaces, DervishD, (Sat Nov 10, 5:04 am)
Re: Coding Style: indenting with tabs vs. spaces, Xavier Bestel, (Sat Nov 10, 5:27 am)
Re: Coding Style: indenting with tabs vs. spaces, DervishD, (Sat Nov 10, 9:50 am)
Re: Coding Style: indenting with tabs vs. spaces, Benny Halevy, (Sun Nov 11, 1:57 am)
Re: Coding Style: indenting with tabs vs. spaces, James Courtier-Dutton, (Sun Nov 11, 2:23 am)
Re: Coding Style: indenting with tabs vs. spaces, Benny Halevy, (Mon Nov 12, 1:13 am)
Re: Coding Style: indenting with tabs vs. spaces, Benny Halevy, (Mon Nov 12, 1:17 am)
Re: Coding Style: indenting with tabs vs. spaces, J. Bruce Fields, (Mon Nov 12, 8:38 am)
Re: Coding Style: indenting with tabs vs. spaces, DervishD, (Mon Nov 12, 9:30 am)