[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Tabs v.s. spaces (was Re: Programming first steps.)

On Mon, Nov 17, 2003 at 11:47:34AM -0600, Chad Walstrom wrote:
> I have a love-hate relationship with the significant whitespace.

I have a hate-hate relationship with it. I much prefer free-style syntax
where the programmer is allowed to use his best judgment on how to indent
the code. Of course, in less-than-ideal projects, or projects with
less-then-ideal programmers, this could result in a mess, but I'm speaking
of personal preference here.

> I have always disliked 8 spaces per tab, because it takes up too much
> screen real estate on an 80 column display.  Whenever I coded in C, I
> set my vi editor to interpret the tabs as 4 spaces.  My mistake in using
> this was displayed when I tried to print with a2ps or enscript, when
> they were once again interpreted as 8 spaces.  Arg! 

I personally insist on 8 spaces per tab, because way too many things break

> I then switched back to using only spaces for indentation, and this
> seems to be a consistent approach, but because personal opinion in
> coding style seems to be a right of passage amongst C coders, I could
> never get anyone to agree with me. ;-)  Even the venerable linux kernel
> only accepts tabs, IIRC[1].

Actually, I do agree with you. I only use tabs for comments, or for
overly-long lines which needs to be broken, but which does not represent
syntactical nesting, eg:

	void some_function_with_a_very_long_name(some_data_type *a,
		some_other_data_type *b, ...) { ... }

For syntactical nesting, I use spaces alone, even if it means I have to
expend extra effort to hit the space bar. The reason I insist on this in
my own coding style is because tabs mixed with spaces in a single stretch
of whitespace are just Pure Evil(tm). They show up all wrong in a viewer
that has a different tab size, and do not behave consistently when you are
re-indenting lines (eg., if a line starts with <tab><tab><space><code>,
and you insert spaces in front of it to indent it, the spaces just get
"eaten" by the tab; and if you are outdenting it, the deleted tab causes
it to outdent too far, but inserting more spaces doesn't compensate for it
because the second tab eats the spaces).

I use tabs for comments only for my own sanity's sake, since otherwise I'd
have to count 40 columns every time I want to comment a line of code.

> Another problem.  Try cut-n-paste in X between code that uses tabs[2].
> Sometimes the tabs are not preserved.  Very odd and annoying.

That's because the terminal settings are b0rked. I personally delete all
programs that cannot cut-n-paste without messing up tabs and spaces.
Unfortunately, this happens a lot on the Winbloxe desktop at work.

> So, tabs v.s. spaces isn't really a concern except when mixing the two.
> If you use eight spaces for all indentation, it won't matter.  If you
> use some other number, it's best to use spaces exclusively.  If you use
> tabs exclusively, changing the appearance in your editor may simply be a
> configuration option away.  What will I use?  I still haven't decided;
> probably tabs/8 spaces. ;-p

For personal pet projects, I use 2 spaces per nesting level. Some people
think that's Pure Evil(tm), although I fully agree with you about wasting
screen real estate in 80 columns (yes, I am one of those freaks who insist
that all code must not have lines longer than 79 characters). 
Nevertheless, for their sake I use 4 spaces per nesting level in group

Also, as an off-topic note, blank lines that contain tabs or spaces are
Pure Evil(tm), especially in code. One of these days I should write a sed
script to eliminate all incarnations of this Pure Evil(tm) from /usr/src.


There are four kinds of lies: lies, damn lies, and statistics.

Reply to: