public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Coding Style: indenting with tabs vs. spaces
@ 2007-11-08 10:36 Benny Halevy
  2007-11-08 15:58 ` Chris Snook
  2007-11-10 12:04 ` DervishD
  0 siblings, 2 replies; 11+ messages in thread
From: Benny Halevy @ 2007-11-08 10:36 UTC (permalink / raw)
  To: lkml

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-11-12 16:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-08 10:36 Coding Style: indenting with tabs vs. spaces Benny Halevy
2007-11-08 15:58 ` Chris Snook
2007-11-12  8:17   ` Benny Halevy
2007-11-10 12:04 ` DervishD
2007-11-10 12:27   ` Xavier Bestel
2007-11-10 16:50     ` DervishD
2007-11-11  9:23       ` James Courtier-Dutton
2007-11-12  8:13         ` Benny Halevy
2007-11-12 15:38           ` J. Bruce Fields
2007-11-12 16:30           ` DervishD
2007-11-11  8:57     ` Benny Halevy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox