Here's an edited version of a comment on tabs and spaces I sent to
our development team that might be useful.
---cut---
Okay, we've had some discussions this morning, and we've got to
deal with tabs and indentation better than we have been.
Some files are simply unviewable right now in various editors
with various settings, and it is time to clean it all up and do
it right.
First, there is a distinction between *tab stops* and *indentation*.
The tab stops define how the editor interprets a tab character in
the file---how many space-equivalents that tab character gives.
The indentation defines how many spaces a nested level should be
indented compared to the previous level. Most editors (including
vim and emacs) use the *indentation*, not the tab stops, in
interpreting how much whitespace to introduce when the user hits
the tab key. That is, when the user hits the tab key, some number
of spaces or tabs will be inserted to match the indentation.
Most modern editors (including emacs and vi) support both concepts.
Unfortunately, most modern programmers (including most of us)
only understand the tab stop concept. This is broken.
Finally, many programs, printers, and so forth are hard-wired to use
8-character tab stops, and there is often no way to work around
this.
There is a clean solution. It's simple and it's elegant and it's
easy.
The rules are as follows.
1. Never ever set your tab stops to something other than 8. This
means, never do (setq tab-width 4) in emacs or set tabstop=4
in vim. If you do, you will create files that will be unusable
by others.
2. Instead, set your indentation to whatever you want, as the
author of a file. This is usually done with
(setq c-basic-indent 4) in emacs, or set softtabstop=4
in vim. This is what you want to do, and if you do this, your
files will work well with everyone.
3. If you want, in your files, add a line such as
/* -*- mode: java; c-basic-indent: 4; -*- */
to force all other emacs users to get *your* desired indentation
so that if they edit your files, their new lines will match your
indentation.
4. I would prefer that none of our source files contain any tab
characters at all since this is what causes the files to display
incorrectly in the different editors, but I'm not going to insist
on this. To do this, in emacs use (setq indent-tabs-mode nil);
in vim use set expandtab. If everyone does as in 1 above, there
won't be a problem in any case.
If you encounter a file that just doesn't display properly for you,
it's probably got a mixture of tabs and spaces and your tab stop is
set differently than (one of the) authors'. This is the crux of
the problem. To fix this, you can set the tab stop of your editor
until it looks most proper, then untabify it (in emacs, untabify;
in vi, set expandtab) and save out the file with no tabs. Then fix
up any remaining indentation problems by hand and check it in.
Unfortunately, the changes will be massive by perforce standards, but
it's probably best to deal with this as early as possible, set the
standard now, and totally prevent problems in the future.
For further reference, consult
http://www.jwz.org/doc/tabs-vs-spaces.html
If anyone has any questions or further discussion is needed, contact
me.
-tom
-----Original Message-----
From: Kief Morris [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 12, 2001 8:43 AM
To: [EMAIL PROTECTED]
Subject: Tabs vs. spaces (was: cvs commit: blah blah blah)
Jon Stevens typed the following on 06:50 PM 4/10/2001 -0700
>
>Craig, does this mean you (finally) aren't using tabs anymore? :-)
>
So, are spaces kosher? The Sun coding standards document (which is the
official Jakarta guideline?) says either is OK, but the mixed tabs and
spaces
format I've found in the Catalina code I've mucked with is a PITA. Can I
just
set my editor to use 4 spaces for tabs and reformat files I work with
accordingly, without spawning a jihad?
Kief